forked from gangireddydanam/saggiapps
-
Notifications
You must be signed in to change notification settings - Fork 1
/
shellscripting
337 lines (240 loc) · 6.79 KB
/
shellscripting
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/opt/automation/scripts/apache/
stopapache.sh
#!/bin/bash
#stopping apache
systemctl stop httpd
---------------------------------
startapache.sh
#!/bin/bash
#starting apache
systemctl start httpd
--------------------------------
restartapache.sh
#!/bin/bash
#stopping apache
systemctl stop httpd
wait 2
systemctl start httpd
========================
restartapache.sh
#!/bin/bash
#stopping apache
/opt/automation/scripts/apache/stopaapche.sh
wait 2
#starting
/opt/automation/scripts/apache/startapache.sh
========================================================
cat staticdeploy.sh
#!/bin/bash
#Author:Name
#Version:1.0
#Purpose: Deployment
cp /home/ec2-user/Coo* /tmp/websites/
sleep 2
cd /tmp/websites/
unzip *.zip
cd CookingSchool-FreeHtmlPageTemplate/
cp -r * /var/www/html/
======================================================================
trouble-shoot
issue with i am role
debug:-
let kwait=$SHUTDOWN_WAIT
count=0;
until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
do
echo -n -e "\n\e[00;31mwaiting for processes to exit\e[00m";
sleep 1
let count=$count+1;
done
chown -R awsadmin.awsadmin /etc
/etc/*
[ec2-user@ip-172-31-35-192 ~]$ sudo su -
sudo: /etc/sudo.conf is owned by uid 1001, should be 0
sudo: /etc/sudo.conf is owned by uid 1001, should be 0
sudo: /etc/sudoers is owned by uid 1001, should be 0
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin
[ec2-user@ip-172-31-35-192 ~]$
=================================
403----same page was comming
=========================================
pem file issues from windows
boot up script failed
make real time processing logs in splunk
cloudtrail--------------------------->ec2--------------->splunk s/w------->dns----------->url----------->SAAS
source="accesslog.txt" host="prd-p-ccxrrhswr5s3" sourcetype="test"
splunk:-
filezilla---->awsadmin---->
ssh
/var/log/httpd----->acess.log ---->/tmp/---777
accounts:-
github
splunk
#!/bin/bash
yum install bind-utils nc telent wget unzip -y
aws-cli.sh
#!/bin/bash
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
unzip awscli-bundle.zip
sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
tomcat-setup
ec2
JAVA-- Installation ---->oracle ----cred->internet
apachetomcat--->Aapahe tomcat site-->internet
setenv.sh--->export JAVA_HOME
start--->
github-structure
#!/bin/bash
yum install bind-utils nc telent wget unzip -y
mkdir /opt/softwares
tempfile=/opt/automation/scripts/tempfile
cd /opt/softwares
aws s3 cp s3://petclinic-uat-deployment-files/jdk-7u80-linux-x64.rpm .
rpm -ivh jdk-7u80-linux-x64.rpm
sleep 5
aws s3 cp s3://petclinic-uat-deployment-files/apache-tomcat-7.0.84.zip .
unzip apache-tomcat-7.0.84.zip -c /opt/
chmod -R 700 /opt/apache-tomcat-7*
rm -rf /opt/apache-tomcat-7*/webapps/*
cd /opt/apache-tomcat-7*/bin/
./startup.sh
cd /opt/softwares
wget http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/10g/r3/cluster/session_state/files/shoppingcart.zip
unzip shoppingcart.zip
cp shoppingcart.war /opt/apache-tomcat-7*/webapps/
ps -ef | grep tomcat >>$tempfile
ls -ltr /opt/apache-tomcat-7*/webapps/ >>$tempfile
status(){
pid=$(tomcat_pid)
if [ -n "$pid" ]
then echo -e "\e[00;32mTomcat is running with pid: $pid\e[00m"
else
echo -e "\e[00;31mTomcat is not running\e[00m"
return 3
fi
}
tomcat_pid() {
echo `ps -fe | grep /opt/tomcat_latest | grep -v grep | tr -s " "|cut -d" " -f2`
}
#!/bin/bash
tempfile=tomcat-setup
spath=/opt/softwares
e=echo
check directory exist or not------------>condition---if
if [ -d $spath ]; then
echo "$spath exists"
else
mkdir $spath
fi
#Downloading s3 content- jdk
$e "i am downloading softwares from s3 bucket"
if
aws s3 cp s3://petclinic-uat-deployment-files/jdk-7u80-linux-x64.rpm $spath
rpm -ivh jdk-7u80-linux-x64.rpm
sleep 5
$e "i am downloading softwares from s3 bucket"
aws s3 cp s3://petclinic-uat-deployment-files/apache-tomcat-7.0.84.zip $spath
unzip apache-tomcat-7.0.84.zip -c /opt/
chmod -R 700 /opt/apache-tomcat-7*
rm -rf /opt/apache-tomcat-7*/webapps/*
cd /opt/apache-tomcat-7*/bin/
./startup.sh
cd /opt/softwares
wget http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/10g/r3/cluster/session_state/files/shoppingcart.zip
unzip shoppingcart.zip
cp shoppingcart.war /opt/apache-tomcat-7*/webapps/
ps -ef | grep tomcat >>$tempfile
ls -ltr /opt/apache-tomcat-7*/webapps/ >>$tempfile
echo $?
======================================================
#!/bin/sh
cp home/testing/present.txt home/testing/future.txt
echo "Copy Code: $? - Successful"
if [ $? != 0 ]; then
echo "Copy Code: $? - Unsuccessful"
else
echo "Copy Code: $? - successful"
fi
========================================================
if [ -d "$LINK_OR_DIR" ]; then
if [ -L "$LINK_OR_DIR" ]; then
# It is a symlink!
# Symbolic link specific commands go here.
rm "$LINK_OR_DIR"
else
# It's a directory!
# Directory command goes here.
rmdir "$LINK_OR_DIR"
fi
fi
===================================================
-e: any kind of archive
-f: file
-h: symbolic link
-r: readable file
-w: writable file
-x: executable file
-s: file size greater than zero
====================================
#!/bin/sh
for i in tomcat1 tomcat2
do
ssh awsadmin@$i 'sudo mkdir -p /opt/automation/scripts'
done
#!/bin/sh
for i in tomcat1 tomcat2
do
ssh awsadmin@$i
done
ssh cacher@cache-server "cd somewhere && untar archive && diff <(ls -lah directory) <(ls -lah other_directory)"
#!/bin/sh
for i in tomcat1 tomcat2
do
scp /opt/apps/shoppingcart.war $i:/opt/tomcat_latest/webapps
done
================================================
vpc
d
sed
awk
cut
sort -nr
diff
uniq
>/dev/null 2>&1
2 error
1=success
$0
$1
crontab
* * * * *
[Minute(0-59)] [hour(0-23)] [Day_of_the_Month(1-31)] [Month_of_the_Year(1-12)] [Day_of_the_Week(0-6)] [command]
*/2 * * * * /root/url_check.sh
root@ip-10-0-0-60 ~]# tail -f /var/log/cron
sort | uniq
first command ouput | input to second cmd
#!/bin/sh
yum -y install httpd
chkconfig httpd on--------------Enabling OS level service/daemon(systemd ,httpd,ntptd,sshd,)
systemctl start httpd
curl http://169.254.169.254/latest/meta-data/
https://github.com/aws-cloudformation/tutorial
autoscaling and
During ec2 provisoning i want to install some package.(user data)--
ssh --public--------- private instance--------yum ------------>internet
============================================================================
Configuration Management
POC--->proof of concept
json/yaml
Rex
SALT
Ansible------------------>
Puppet
Chef
---------------->frameworks
key and value
lists
dictionary
tasks------->action ,description , name
===============================================================================