shell脚本收藏
2015-07-03 10:37
686 查看
#!/bin/sh if [ "$#" -ne "1" ]; then echo "usage: $0 <svn_url>" exit 1 fi release_v=$(date +%Y%m%d) svn_user="deploy" svn_passwd=“*******” svn_url=$1 target_path="res" svn checkout --non-interactive --trust-server-cert --username "${svn_user}" --password "${svn_passwd}" "${svn_url}" "${target_path}" mkdir $release_v mv res $release_v cp crossdomain.xml $release_v
#!/bin/sh if [[ $UID -ne 0 ]]; then echo "You must run as root" exit fi localtime=`date +%Y%m%d_%H%M` backup_server_name=s1 port=($(netstat -lntp | grep redis-server | awk '{print $4}' | awk '{split($0,ports,":");print ports[length(ports)]}' | sort | uniq)) num=${#port[@]} backup_file_name_6379=redis_${backup_server_name}_6379_${localtime}.tar.gz backup_file_name_6380=redis_${backup_server_name}_6380_${localtime}.tar.gz backup_path=/data/backup/redis/local if [[ $num -eq 0 ]];then echo -e "n33[40;31m No redis server is running33[0mn" exit 1 fi #压缩 for i in ${port[@]};do if [ ${i} -eq 6379 ]; then cd /data/redis/var tar czvf ${backup_file_name_6379} dump.rdb elif [ ${i} -eq 6380 ]; then cd /data/redis/var-6380 tar czvf ${backup_file_name_6380} dump.rdb else exit 1 fi done #移动 if [ ! -d ${backup_path} ]; then mkdir -p ${backup_path} fi for i in ${port[@]};do if [ ${i} -eq 6379 ]; then mv /data/redis/var/${backup_file_name_6379} ${backup_path} fi if [ ${i} -eq 6380 ];then mv /data/redis/var-6380/${backup_file_name_6380} ${backup_path} fi done #同步 #rsync -avIz $backup_path/*.tar.gz 192.168.1.9:/data/s1_server/redis/s1/ #清理 find ${backup_path}/ -type f -name "*.tar.gz" -ctime +30 -exec rm -rf {} ;
#!/bin/sh # # php-fpm - this script starts and stops the php-fpm daemin # # chkconfig: - 85 15 # processname: php-fpm # config: /usr/local/php/etc/php-fpm.conf set -e #PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC="php-fpm daemon" NAME=php-fpm DAEMON=/usr/local/php/sbin/$NAME #这里设成自己的目录 CONFIGFILE=/usr/local/php/etc/php-fpm.conf #这里设成自己的目录 PIDFILE=/var/run/$NAME.pid #这里设成自己的目录 SCRIPTNAME=/etc/init.d/$NAME #这里设成自己的目录 # If the daemon file is not found, terminate the script. test -x $DAEMON || exit 0 d_start(){ $DAEMON -y $CONFIGFILE || echo -n " already running" } d_stop(){ kill -QUIT `cat $PIDFILE` || echo -n " no running" } d_reload(){ kill -USR2 `cat $PIDFILE` || echo -n " could not reload" } case "$1" in start) echo -n "Starting $DESC: $NAME" d_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" d_stop echo "." ;; reload) echo -n "Reloading $DESC configuration..." d_reload echo "Reloaded." ;; restart) echo -n "Restarting $DESC: $NAME" d_stop # Sleep for two seconds before starting again, # this should give the nginx daemon some time to perform a graceful stop sleep 2 d_start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload)" >&2 exit 3 ;; esac exit 0
3.随机用户密码生成 i passwd.sh #创建一个 10 位的随机的密码。。。 #!/bin/bash a=(a b c d e A B C D E F @ $ % ^ 0 1 2 3 4 5 6 7 8 9) for ((i=0;i<10;i++));do echo -n ${a[$RANDOM % ${#a[@]}]} done echo vi useradd.sh #创建5个账号,引用了随机的密码。 #!/bin/bash i=1 while [ $i -le 5 ] do useradd red$i a=`sh ./passwd.sh` echo " red$i:$a " >> sumuserpasswd echo "~~~~~~~~~~~" >> sumuserpasswd echo red$i:$a|chpasswd # echo $a | passwd –-stdin red"$i" let i++ done自己用的
1.查看本机跑的进程
ps -ef|awk '{if($2>2023){print $0}}'|awk -F " " '{OFS=" " ;for(i=8;i<=NF;i++)printf $i" ";if (NF > 7) printf "\n";}'|egrep -v "awk|-bash|pts|crond|flush|jbd2|udevd|ps|libexec|mingetty|gdm-password|gnome-power-manager|ext4-dio-unwrit|pulseaudio|metacity|gnome|dbus-daemon|dbus-launch|console-kit-daemon|Xorg|gdm-binary|rhsmcertd|atd|CMD|abrtd|sshd|rsyslogd"|uniq
4.app简单发布脚本
#!/bin/bash #Date=`date +%Y-%m-%d-%k-%M-%S` . /etc/init.d/functions Date=`date +%Y-%m-%d` scapk="1.apk" project=$2 PRO=$1 Appdir="/home/app/$PRO" [ ! -d $Appdir ] && mkdir -p $Appdir && mkdir -p $Appdir/{old,new} function Svn() { if [ -f $Appdir/newversion.txt ];then oldappname=`cat $Appdir/newversion.txt` yes|cp -r $Appdir/newversion.txt $Appdir/oldversion.txt fi cd $Appdir svn checkout http://svn.com/svn/a/trunk/app/$project --no-auth-cache --username 'test' --password '123456' cd $project #lastre=`ls -l --color=auto -rt|tail -1|awk '{print $NF}'` lastre=`ls -l|tail -1|awk '{print $NF}'` cd $lastre appname=`ls -l|grep ".*release*.apk"|awk '{print $NF}'` echo "$appname" > $Appdir/newversion.txt cp -r $appname $Appdir/new yes|cp -r $scapk $Appdir/old/$oldappname yes|cp -r $project/$lastre/$appname $scapk cd $Appdir find . -name "*.apk" -type f -mtime +30 -exec rm -rf {} \; } case $1 in svn) Svn ;; *) printf "sh -x app.sh svn c c \n" esac5.检测是否发送邮件
if [ -f /root/.bash_profile ];then source /root/.bash_profile fi sdate=`date "+%Y-%m-%d %H:%M:%S"` sql="use db;select status,create_time from atable where round((UNIX_TIMESTAMP('${sdate}')-UNIX_TIMESTAMP(create_time))/3600)>24"; MysqlUser='user' PassWord='password' MysqlCmd="mysql -h host -u"$MysqlUser" -p"$PassWord"" ddate=`date "+%H:%M:%S"` alert_value=1 problem_file='sql.txt' if [ -e ${problem_file}-$alert_value ];then cd /home/shell datefile=`stat ${problem_file}-$alert_value|grep Modify|awk '{print $2}'` datenow=`date "+%Y-%m-%d"` [ $datefile != $datenow ] && rm -rf ${problem_file}-$alert_value fi if [ -e ${problem_file}-$alert_value ];then exit 0 fi if [ ! -e ${problem_file}-$alert_value ];then cd /home/shell $MysqlCmd -e "$sql">./sql.txt sleep 5 $MysqlCmd -e "$sql">./sql.txt fi problem_value=`cat $problem_file|wc -l` if [ $problem_value -gt $alert_value ] && [ ! -e ${problem_file}-$alert_value ];then subject=`echo -n "subject" | base64` /usr/local/zabbix/scripts/sendEmail -f test@a.com -t dest@a.com -s smtp.a.com -u "=?utf-8?b?$subject?=" -o message-content-type=text -o message-charset=utf-8 -xu otojk.admin@a.com -xp password -m "messages" touch ${problem_file}-$alert_value fi00 */1 * * * root /bin/bash /home/shell/test.sh >/dev/null 2>&1 &
相关文章推荐
- android wifi 无线调试
- 运维入门
- 动态清空 nohup 输出文件
- install scrapy with pip and easy_install
- Linux Shell常用技巧
- shell字符串操作详解
- Shell中删除某些文件外所有文件的3个方法
- Ruby中执行Linux shell命令的六种方法详解
- VB使用shell函数打开外部exe程序的实现方法
- Shell编程的一些知识集合
- Shell中的for和while循环详细总结
- 什么是Shell?Shell脚本基础知识详细介绍
- Shell脚本中引用、调用另一个脚本文件的2种方法
- Shell脚本解压rpm软件包
- Shell脚本实现复制文件到多台服务器的代码分享
- Shell脚本实现批量替换文件内容
- Shell脚本实现的一个简易Web服务器例子分享
- linux Shell学习笔记第五天
- Perl 获取shell命令的执行结果
- Shell脚本中非交互式修改密码的两种方法