SHELL学习之sftp输入重定向
#!/bin/bash#this is a scripts that auto sftp accounts' info to server
#version 0.3
#获取IP和日期
DATE=$(date +%Y-%m-%d)
#arg=`ifconfig eth0 |grep "inet addr"| cut -f 2 -d ":"|cut -f 1 -d " "`
#IP=`ifconfig eth0 | grep "net add" | awk '{print $2}' |sed 's/addr://g'`
i=0
while [ $i -lt 5 ]
do
IP=`ifconfig eth"$i" | grep "net add" | awk '{print $2}' |sed 's/addr://g'`
if [ -z "$IP" ];then
:
else
break
fi
let i=$i+1
done
#拷贝和打包
cp /etc/passwd /opt/
cp /etc/shadow /opt/
mv /opt/passwd /opt/"$IP"-"$DATE"passwd
mv /opt/shadow /opt/"$IP"-"$DATE"shadow
tar -cf "$IP"-"$DATE".tar "$IP"*
#sftp上传
sftp 10.108.7.23/dev/null 2>&1
if [ $?=0 ];then
exit
else
echo "* * 20 * * bash /opt/userchk >>/dev/null 2>&1">>/var/spool/cron/root
fi
exit 0
页:
[1]