shell脚本例子】的更多相关文章

4.几个常用的shell脚本例子    4.0.在写脚本(同样适用在编程的时候),最好写好完善的注释    4.1.kill_processes.sh(一个杀死进程的脚本) #!/bin/bash current_PID=$$ ps -aux | grep "/usr/sbin/httpd" | grep -v "grep" | awk '{print $2}' > /tmp/${current_PID}.txt for pid in `cat /tmp/${…
# vi xx.sh 退出并保存 # chmod +x xx.sh # ./xx.sh -2. 调试脚本的方法 # bash -x xx.sh 就可以调试了 . -1. 配置 secureCRT 的设置 ( 我用的是 6.2.3 build313 版本 , 汉化版 ) 选项 -> 会话选项 (S)...-> 终端 -> 仿真 -> 终端 (T)-> 把 VT100 改成 Xterm-> 点中 ANSI 颜色 (A) 和使用颜色方案 (U) 复选框 . 这样就有颜色显示了…
练习一:写一个脚本 .设定变量FILE的值为/etc/passwd .依次向/etc/passwd中的每个用户问好,并且说出对方的ID是什么 形如:(提示:LINE=`wc -l /etc/passwd | cut -d" " -f1`) Hello,root,your UID . .统计一个有多少个用户 答案一:#!/bin/bash file="/etc/passwd" LINES=`wc -l $file | cut -d" " -f1`…
#!/bin/sh   str="####" echo $1 | grep $str 1>/dev/null if [ `echo $?` -eq 0 ] then   echo ${1//$str/""} else   echo $2 not present in $1 fi…
目录 Linux和Shell简介 Linux是一套可免费使用和自由传播的类UNIX操作系统.Shell是一种具备特殊功能的程序,它提供了用户与内核进行交互操作的一种接口.它接收用户输入的命令,并把它送入内核去执行.内核是Linux系统的核心部分,从开机自检时就驻留在计算机的内存中,直到计算机关闭为止,而用户的应用程序存储在计算机的硬盘上,仅当需要时才被调入内存.Shell是一种命令解释程序,当用户登录Linux系统时,Shell就会被调入内存执行.Shell独立于内核,它是连接内核和应用程序的桥…
与其他编程语言类似,Shell支持for循环. for循环一般格式为: for 变量 in 列表 do command1 command2 ... commandN done 列表是一组值(数字.字符串等)组成的序列,每个值通过空格分隔.每循环一次,就将列表中的下一个值赋给变量.in 列表是可选的,如果不用它,for 循环使用命令行的位置参数. 下面演示几个使用for的shell脚本例子 1.顺序输出当前列表中的数字: do echo "The value is: $loop" don…
这个例子演示了如何在shell脚本中执行多个sql来操作数据库表. #! /bin/sh USER_HOME=/home/`whoami` . /etc/profile if [ -f ${USER_HOME}/.bash_profile ]; then . ${USER_HOME}/.bash_profile fi mysql -h -ujifei30 -pNapnUszJD -Dtpssprod <<EOF select table_name from information_schema…
/** * 运行shell脚本 * @param shell 需要运行的shell脚本 */ public static void execShell(String shell){ try { Runtime rt = Runtime.getRuntime(); rt.exec(shell); } catch (Exception e) { e.printStackTrace(); } } /** * 运行shell * * @param shStr * 需要执行的shell * @return…
eg: Expect: 1.用环境变量RANDOM随机生成一个100以内的随机数 2.read读取当前输入 3.当前输入对比随机生成的数 4.当两个数相等时跳出苏循环,并计数(比较n次结果才相等) #!/bin/bash i= num=$(expr $RANDOM % ) echo $num while true do let i++ read -p "Please input number(1-100):" digit if [ $digit -eq $num ]; then ech…
1.在shell脚本执行python脚本时,需要通过python脚本的返回值来判断后面程序要执行的命令 例:有两个py程序  hello.py 复制代码代码如下: def main():    print "Hello" if __name__=='__main__':    main()world.py def main():    print "Hello" if __name__=='__main__':    main() shell 脚本 test.sh…