? 读取文件的时间
#!/bin/bash
for file in `ls /root`
do
stat $file>1.txt
sed -n "7p" 1.txt>2.txt
usetime= awk -F ":" ‘{print $2}‘ 2.txt
echo "time="$file $usetime
done
? 读取文件的每行while语句。
cat afile | while read oneline
do
echo $oneline
done
? 读取文件的每行for语句。
for i in `cat afile`
do
echo $i
done
? 自动添加用户
useradd test
passwd test<<eof
111111
111111
eof
? 自动杀死进程
ps -a | grep ‘‘ | awk ‘{print $1}‘ | xargs -i kill 9 {}
? 保留七天的文件
#! /bin/bash
for file in `ls /orabak`
do
if [[ ${file:0:2} == "db" ]];then
fdate=${file:10:8}
mydate=`date +%Y%m%d -d "-7 day"`
if [[ $fdate < $mydate ]];then
rm -rf $file;
else
echo $file;
fi
else
fdate=${file:12:8}
mydate=`date +%Y%m%d -d "-7 day"`
if [[ $fdate < $mydate ]];then
rm -rf $file;
else
echo $file;
fi
fi
done
? 查看表的字段
su - oracle << BO
sqlplus / as sysdba<<EOF
desc user_tables;
exit;
EOF
几个 bash shell的例子,布布扣,bubuko.com
原文:http://blog.csdn.net/clark_xu/article/details/35999337