shell 编程实战

在这里插入图片描述

#!/bin/bash
while true
do
echo "input path:"
read path
if [ $path = "q" ]
then break
elif [ -d $path ]
then
 
for file in `ls $path`
do
file=$path/$file
if [ -d $file ]
then echo "${file}_d"
elif [ -b $file ]
then echo "${file}_b"
elif [ -L $file ]
then echo "${file}_|"
elif [ -f $file ]
then echo "${file}_-" 
else echo "${file}_c"
fi

done

else echo "illegal input"
fi
done

在这里插入图片描述

#!/bin/bash
while true
do
echo "Use one of the following options
P:To display current directory
S:To display the name of running file
D:To display today's date and present time(如:2017-04-26 05:45:12) 
L:To see the list of files in your present working directory
W:To see who is logged in
I:To see the ip address of this local machine
Q:To quit this program
Enter your option and hit:"
read in
case $in in
P|p) pwd ;;
S|s) echo $0 ;;
D|d) date "+%Y-%m-%d %H:%M:%S";;
L|l) ls ;;
W|w) w ;;
I|i) ip add ;;
Q|q) break ;; 
*) echo "!!!!!illegal input!!!!!!!!"
esac
done


在这里插入图片描述

#!/bin/bash
while true
do
echo "input path:"
read path
if [ $path = "q" ]
then break
elif [ -d $path ]
then
 
for file in `ls $path`
do
file=$path/$file
if [ -d $file ]
then echo "${file}_d"
elif [ -b $file ]
then echo "${file}_b"
elif [ -L $file ]
then echo "${file}_|"
elif [ -f $file ]
then echo "${file}_-" 
else echo "${file}_c"
fi

done

else echo "illegal input"
fi
done

在这里插入图片描述

#!/bin/bash
function func(){
a=$1
echo -e 
until [ $a -eq 0 ]
do
   echo -n "$a "
   let a=$a-1
done
}
while true
do
echo  "please,input a number:"
read b
until [ $b -le 0 ]
do
   func $b
   let b=$b-1
done
echo -e
done

30 8 * * * /home/zkpk/shell/startftp.sh
30 23 * * * systemctl stop vsftpd
50 23 * * * /home/zkpk/shell/tarfile.sh
30 8-23/1 * * * /home/zkpk/shell/pingbaidu.sh

#! /bin/bash
# /home/zkpk/shell/startftp.sh
# 开启vsftpd
systemctl start vsftpd
if [ $? -eq 1 ]; then
echo "start ftp error" | mail -s "error" root
else 
ps -ef | grep vsftpd | head -n1 >> /var/ftp/"`date +%Y-%m-%d`".log
fi

#! /bin/bash
# /home/zkpk/shell/pingbaidu.sh
#ping 百度
ping -c 4 www.baidu.com >> /var/ftp/"`date +%Y-%m-%d`".log

#! /bin/bash
# /home/zkpk/shell/tarfile.sh
# 压缩文件
sleep 30s 
tar -czvf "`date +%Y-%m-%d`".tar.gz /var/ftp
chmod 400 "`date +%Y-%m-%d`".tar.gz
mv "`date +%Y-%m-%d`".tar.gz  /root
rm -rf /var/ftp/*

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值