发一下牢骚和主题无关:
#Shell工具 #日记件文 #编辑 #vi datelog.sh #查看件文容内 [root@localhost 0418]# cat datelog.sh #!/bin/bash #datelog.sh #前当的期日 current_date=`date "+%Y%m%d"` #天今的日记件文名 todaylog="log/${current_date}.log} #如果日记件文不存在,创立一个 if [ ! -f $todaylog ] then touch $todaylog fi #出输日记到日记件文 log_time_format=`date "+%Y-%m-%d %T"` echo "${log_time_format} 命令开始" >>$todaylog # # command blocks sleep 4 # #出输日记到日记件文 log_time_format=`date "+%Y-%m-%d %T"` echo "${log_time_format} 命令束结" >>$todaylog #执行 [root@localhost 0418]# ./datelog.sh #查看前当期日 [root@localhost 0418]# date Thu Apr 18 11:35:52 CST 2013 You have new mail in /var/spool/mail/root #查看date帮助手册 [root@localhost 0418]# man date #编辑 vi processlog.sh #转变权限 [root@localhost 0418]# chmod 755 processlog.sh #启动httpd务服 [root@localhost 0418]# service httpd start Starting httpd: perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LANG = "en_US.en" are supported and installed on your system. perl: warning: Falling back to the standard locale ("C"). [ OK ] #查看httpd进程详细信息并去除grep [root@localhost 0418]# ps -aux|grep "/usr/sbin/httpd"|grep -v " grep " root 19202 1.9 3.3 19656 8624 ? S 12:09 0:00 /usr/sbin/httpd #查看httpd进程详细信息并去除grep、印打进程号 [root@localhost 0418]# ps -aux|grep "/usr/sbin/httpd"|grep -v "grep"|awk '{print $2}' 19202 #执行 [root@localhost 0418]# ./processlog.sh #查看 [root@localhost 0418]# cat /t tftpboot tmp #查看tmp目录,发明19304.txt件文 [root@localhost 0418]# cat /tmp/ .X0-lock .X11-unix .fam_socket .font-unix .gdm_socket .iroha_unix 19304.txt OSL_PIPE_0_SingleOfficeIPC_e31798b4554fdedd4fea48cd4e93b7 VMwareDnD jd_sockV4 orbit-root orbit-student ssh-XXCs45Ko vmware-root #查看19304.txt容内 [root@localhost 0418]# cat /tmp/19304.txt 19202 #手动删除 [root@localhost 0418]# rm -f /tmp/19304.txt #执行 [root@localhost 0418]# ./processlog.sh rm -f /tmp/19421.txt #从新查看,发明没有容内 [root@localhost 0418]# cat /tmp/19421.txt cat: /tmp/19421.txt: No such file or directory #信号 #查看有所信号 [root@localhost 0418]# kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR 31) SIGSYS 33) SIGRTMIN 34) SIGRTMIN+1 35) SIGRTMIN+2 36) SIGRTMIN+3 37) SIGRTMIN+4 38) SIGRTMIN+5 39) SIGRTMIN+6 40) SIGRTMIN+7 41) SIGRTMIN+8 42) SIGRTMIN+9 43) SIGRTMIN+10 44) SIGRTMIN+11 45) SIGRTMIN+12 46) SIGRTMIN+13 47) SIGRTMIN+14 48) SIGRTMIN+15 49) SIGRTMAX-14 50) SIGRTMAX-13 51) SIGRTMAX-12 52) SIGRTMAX-11 53) SIGRTMAX-10 54) SIGRTMAX-9 55) SIGRTMAX-8 56) SIGRTMAX-7 57) SIGRTMAX-6 58) SIGRTMAX-5 59) SIGRTMAX-4 60) SIGRTMAX-3 61) SIGRTMAX-2 62) SIGRTMAX-1 63) SIGRTMAX #查看httpd进程详细信息 [root@localhost 0418]# ps -ef |grep "httpd" root 19202 1 0 12:09 ? 00:00:00 /usr/sbin/httpd apache 19205 19202 0 12:09 ? 00:00:00 [httpd] apache 19206 19202 0 12:09 ? 00:00:00 [httpd] apache 19207 19202 0 12:09 ? 00:00:00 [httpd] apache 19208 19202 0 12:09 ? 00:00:00 [httpd] apache 19209 19202 0 12:09 ? 00:00:00 [httpd] apache 19210 19202 0 12:09 ? 00:00:00 [httpd] apache 19211 19202 0 12:09 ? 00:00:00 [httpd] apache 19212 19202 0 12:09 ? 00:00:00 [httpd] root 19533 2658 0 12:23 pts/0 00:00:00 grep httpd #查看httpd进程详细信息并去除grep [root@localhost 0418]# ps -ef |grep "httpd"|grep -v "grep" root 19202 1 0 12:09 ? 00:00:00 /usr/sbin/httpd apache 19205 19202 0 12:09 ? 00:00:00 [httpd] apache 19206 19202 0 12:09 ? 00:00:00 [httpd] apache 19207 19202 0 12:09 ? 00:00:00 [httpd] apache 19208 19202 0 12:09 ? 00:00:00 [httpd] apache 19209 19202 0 12:09 ? 00:00:00 [httpd] apache 19210 19202 0 12:09 ? 00:00:00 [httpd] apache 19211 19202 0 12:09 ? 00:00:00 [httpd] apache 19212 19202 0 12:09 ? 00:00:00 [httpd] #杀死进程19212 [root@localhost 0418]# kill -s SIGKILL 19212 [root@localhost 0418]# ps -ef |grep "httpd"|grep -v "grep" root 19202 1 0 12:09 ? 00:00:00 /usr/sbin/httpd apache 19205 19202 0 12:09 ? 00:00:00 [httpd] apache 19206 19202 0 12:09 ? 00:00:00 [httpd] apache 19207 19202 0 12:09 ? 00:00:00 [httpd] apache 19208 19202 0 12:09 ? 00:00:00 [httpd] apache 19209 19202 0 12:09 ? 00:00:00 [httpd] apache 19210 19202 0 12:09 ? 00:00:00 [httpd] apache 19211 19202 0 12:09 ? 00:00:00 [httpd] #功能同上 [root@localhost 0418]# kill -9 19211 #从新查看httpd进程详细信息并去除grep ,发明没有该进程,说明被终止 [root@localhost 0418]# ps -ef |grep "httpd"|grep -v "grep" root 19202 1 0 12:09 ? 00:00:00 /usr/sbin/httpd apache 19205 19202 0 12:09 ? 00:00:00 [httpd] apache 19206 19202 0 12:09 ? 00:00:00 [httpd] apache 19207 19202 0 12:09 ? 00:00:00 [httpd] apache 19208 19202 0 12:09 ? 00:00:00 [httpd] apache 19209 19202 0 12:09 ? 00:00:00 [httpd] apache 19210 19202 0 12:09 ? 00:00:00 [httpd] #挂起进程 [root@localhost 0418]# kill -s SIGHUP 19210 #查看httpd进程详细信息并去除grep [root@localhost 0418]# ps -ef |grep "httpd"|grep -v "grep" root 19202 1 0 12:09 ? 00:00:00 /usr/sbin/httpd apache 19205 19202 0 12:09 ? 00:00:00 [httpd] apache 19206 19202 0 12:09 ? 00:00:00 [httpd] apache 19207 19202 0 12:09 ? 00:00:00 [httpd] apache 19208 19202 0 12:09 ? 00:00:00 [httpd] apache 19209 19202 0 12:09 ? 00:00:00 [httpd] #从新查看查看httpd进程详细信息并去除grep [root@localhost 0418]# ps -ef |grep "httpd"|grep -v "grep" root 19202 1 0 12:09 ? 00:00:00 /usr/sbin/httpd apache 19205 19202 0 12:09 ? 00:00:00 [httpd] apache 19206 19202 0 12:09 ? 00:00:00 [httpd] apache 19207 19202 0 12:09 ? 00:00:00 [httpd] apache 19208 19202 0 12:09 ? 00:00:00 [httpd] apache 19209 19202 0 12:09 ? 00:00:00 [httpd] #杀死子进程或者父进程下的有所子进程 [root@localhost 0418]# kill -1 19209 #查看httpd进程详细信息并去除grep [root@localhost 0418]# ps -ef |grep "httpd"|grep -v "grep" root 19202 1 0 12:09 ? 00:00:00 /usr/sbin/httpd apache 19205 19202 0 12:09 ? 00:00:00 [httpd] apache 19206 19202 0 12:09 ? 00:00:00 [httpd] apache 19207 19202 0 12:09 ? 00:00:00 [httpd] apache 19208 19202 0 12:09 ? 00:00:00 [httpd] apache 19616 19202 0 12:26 ? 00:00:00 [httpd] #查看httpd进程详细信息并去除grep [root@localhost 0418]# ps -ef |grep "httpd"|grep -v "grep" root 19202 1 0 12:09 ? 00:00:00 /usr/sbin/httpd apache 19205 19202 0 12:09 ? 00:00:00 [httpd] apache 19206 19202 0 12:09 ? 00:00:00 [httpd] apache 19207 19202 0 12:09 ? 00:00:00 [httpd] apache 19208 19202 0 12:09 ? 00:00:00 [httpd] apache 19616 19202 0 12:26 ? 00:00:00 [httpd] #束结进程号为19202的进程 [root@localhost 0418]# kill -1 19202 #查看httpd进程详细信息并去除grep [root@localhost 0418]# ps -ef |grep "httpd"|grep -v "grep" root 19202 1 0 12:09 ? 00:00:00 /usr/sbin/httpd exit crtl+D退出前当shell #trap捕捉信号 #立建件文夹0419 mkdir 0419 #进入该目录 cd 0419 #拷贝0418有所件文到前当目录 [root@localhost 0419]# cp ../0418/* . #编辑 [root@localhost 0419]# vi trap1.sh #查看容内 [root@localhost 0419]# cat trap1.sh #!/bin/bash #trap1.sh #注意此处为单引号,不是反引号 trap ‘exitprocess’ 2 LOOP=0 function exitprocess() { echo "You just hit <CRTL-C>, at number $LOOP" echo "I will now exit" exit 1 } while : do LOOP=$[$LOOP+1] echo $LOOP done #转变权限 [root@localhost 0419]# chmod 755 trap1.sh #执行 [root@localhost 0419]# ./trap1.sh #另一个终端查看进程 [root@localhost 0419]# ps –ef root 4221 2113 0 15:57 ? 00:00:00 /usr/sbin/sshd root 4241 4221 0 15:58 pts/1 00:00:00 -bash root 4834 4180 6 16:19 pts/0 00:00:00 /bin/bash ./trap1.sh #束结进程 kill -2 4834 #执行终端印打信息 You just hit <CRTL-C>, at number 38383 I will now exit #从新编辑 [root@localhost 0419]# vi trap1.sh #查看容内,加增眠休调用 [root@localhost 0419]# cat trap1.sh #!/bin/bash #trap1.sh trap ‘exitprocess’ 2 LOOP=0 function exitprocess() { echo "You just hit <CRTL-C>, at number $LOOP" echo "I will now exit" exit 1 } while : do LOOP=$[$LOOP+1] echo $LOOP #加增码代 sleep 1 done #执行 [root@localhost 0419]# ./trap1.sh root 5245 4180 0 16:35 pts/0 00:00:00 /bin/bash ./trap1.sh #另一个终端,束结进程 kill -4 5245 #前当终端,示显信息 Illegal instruction #不做任何理处 kill -3 5305 #会做理处 kill -2 5305 #拷贝件文 [root@localhost 0419]# cp trap1.sh trap2.sh #查看容内 [root@localhost 0419]# cat trap2.sh #!/bin/bash #trap2.sh LOOP=0 trap 'exitprocess' 2 HOLD1=/tmp/ho1d1.$$ HOLD2=/tmp/hold2.$$ function exitprocess() { echo -e "\nRecived Interrupt ..." echo -n "Do you really wish to exit?(Y?N)" read ANS case $ANS in Y|y) rm_tmp_file ;; N|n) ;; *) exitprocess ;; esac } function rm_tmp_file() { echo "<CRTL-C> detected .. Now cleaning up ...wait" rm /tmp/*.$$ 2>/dev/null exit 1 } while : do LOOP=$[$LOOP+1] echo $LOOP df>>$HOLD1 ps -xa >>$HOLD2 sleep 1 done #执行 [root@localhost 0419]# ./trap2.sh 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 Recived Interrupt ... Do you really wish to exit?(Y?N)N 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 Recived Interrupt ... Do you really wish to exit?(Y?N)y <CRTL-C> detected .. Now cleaning up ...wait #查看tmp目录下的容内 ls -al /tmp/ -rw-r--r-- 1 root root 3816 Apr 19 16:50 ho1d1.5503 -rw-r--r-- 1 root root 3816 Apr 19 16:50 ho1d2.5503 #另一个终端查看进程 ps –ef #束结进程 kill -2 5503 #eval #执行 [root@localhost 0419]# MYFILE="cat myfile"; `eval $MYFILE` -bash: total: command not found #编辑 vi myfile #查看容内 [root@localhost 0419]# cat myfile ls –al #执行 [root@localhost 0419]# MYFILE="cat myfile"; `eval $MYFILE` total 32 drwxr-xr-x 2 root root 4096 Apr 19 16:54 . drwxr-xr-x 15 root root 4096 Apr 19 15:58 .. -rwxr-xr-x 1 root root 431 Apr 19 15:59 awkif.sh -rwxr-xr-x 1 root root 435 Apr 19 15:59 datelog.sh -rw-r--r-- 1 root root 7 Apr 19 16:54 myfile -rwxr-xr-x 1 root root 391 Apr 19 15:59 processlog.sh -rwxr-xr-x 1 root root 210 Apr 19 16:35 trap1.sh -rwxr-xr-x 1 root root 484 Apr 19 16:45 trap2.sh #从新编辑 [root@localhost 0419]# vi myfile #查看容内 [root@localhost 0419]# cat myfile ls #从新执行 [root@localhost 0419]# MYFILE="cat myfile"; `eval $MYFILE` awkif.sh datelog.sh myfile processlog.sh trap1.sh trap2.sh #可以不应用量变 [root@localhost 0419]# eval `cat myfile` awkif.sh datelog.sh myfile processlog.sh trap1.sh trap2.sh #logger #查看messages容内 [root@localhost 0419]# cat /var/log/messages #向日记件文加增容内 [root@localhost 0419]# logger -i "chinaitlab shenzhen" Apr 19 17:01:09 localhost root[6179]: chinaitlab shenzhen [root@localhost 0419]# logger -p 19 -i "chinaitlab shenzhen" #再次查看 [root@localhost 0419]# cat /var/log/messages Apr 19 17:01:09 localhost root[6179]: chinaitlab shenzhen Apr 19 17:01:56 localhost root[6199]: chinaitlab shenzhen #向日记件文加增容内 [root@localhost 0419]# logger -p 1 -i "chinaitlab shenzhen" #再次查看 [root@localhost 0419]# cat /var/log/messages Apr 19 17:01:09 localhost root[6179]: chinaitlab shenzhen Apr 19 17:01:56 localhost root[6199]: chinaitlab shenzhen Apr 19 17:02:25 localhost root[6201]: chinaitlab shenzhen
@Wentasy 博文仅供参考,欢送大家来访。有如错误的地方,望希批评指正。原创博文如需转载请注明出处,谢谢 :) [CSDN博客] |
文章结束给大家分享下程序员的一些笑话语录: Google事件并不像国内主流媒体普遍误导的那样,它仅仅是中国Z府和美国公司、中国文化和美国文化甚至中国人和美国人之间的关系,是民族主义和帝国主义之间的关系;更重要的是,它就是Z府和公司之间的关系,是权力管制和市场自由之间的关系。从这个意义上说,过度管制下的受害者,主要是国内的企业。Google可以抽身而去,国内的企业只能祈望特区。www.ishuo.cn