linux 學習——Shell入門(實例一)紙上得來終覺淺
紙上得來終覺淺,絕知此事要躬行.——陸游(宋)
知之愈明,則行之愈篤;行之愈篤,則知之益明.——朱熹(宋)
一、ssh執行遠端操作
命令格式
ssh -p $port $user@$p 'cmd'
$port : ssh連接埠號
$user: ssh連接用戶名
$ip:ssh連接的ip位址
cmd:遠端伺服器需要執行的操作
示例腳本
二、判斷一檔是不是字元設備檔,如果是將其拷貝到 /dev 目錄下。
命令格式
#!/bin/sh
FILENAME=
echo “Input file name:”
read FILENAME
if [ -c "$FILENAME" ]
then
cp $FILENAME /dev
fi
三、編寫shell程式,實現自動刪除50個帳號的功能。
命令格式
#!/bin/sh
i=1
while [ $i -le 50 ]
do
userdel -r stud${i}
i=$(($i+1 ))
done