目錄
1.進程監(jiān)控
2.判斷QQ是否運行
3.查看某目錄下的文件
4.從第幾列保存
5.普通用戶切換到root
6.自動登錄到遠程服務(wù)器
7.調(diào)用腳本文件
8.保存ps結(jié)果
9.輸出所有進程
10.查看某個文件權(quán)限
1.進程監(jiān)控
MAIN_EXISTS=`sudo launchctl list | grep org.apple.main.getdates`
echo "$MAIN_EXISTS"
if [ -n "$MAIN_EXISTS" ]; then
echo "進程org.apple.main.getdates已開啟,無需關(guān)心"
else
cd /System/Library/LaunchDaemons/
sudo launchctl load com.apple.main.plist
echo "進程org.apple.main.getdates不存在,開啟進程"
fi
2.判斷QQ是否運行
#/bash/bin
PROCESS_EXISTS=`ps -fe | grep QQ.app | grep -v grep`
echo "$PROCESS_EXISTS"
if [ -n "$PROCESS_EXISTS" ]; then
echo "QQ.app 已開啟"
else
open /Applications/QQ.app
fi
3.查看某目錄下的文件
#/bin/sh
declare -a array
array=$(ls /Applications)
for var in ${array}
do
PROCESS_EXISTS=`ps -fe | grep ${var} | grep -v grep`
if [ -n "$PROCESS_EXISTS" ];then
${var} 2>&1 |tee -a /Users/didi/Desktop/Les/tt.txt
echo ${var}
else
echo ""
fi
done
4.從第幾列保存
ps -ef|grep /Applications/ |awk '{print $8}'
5.普通用戶切換到root
#!/usr/bin/expect -f
spawn su -
expect "Please enter password:"
send "password"
interact
6.自動登錄到遠程服務(wù)器
#!/usr/bin/expect
set timeout 30
spawn ssh -l username 192.168.1.1
expect "password:"
send "ispass\r"
interact
7.調(diào)用腳本文件
iOS 調(diào)用腳本
execlp("/Users/didi/Desktop/RELOAD/RELOAD/reload.sh",NULL);
8.保存ps結(jié)果
#ps -A 2>&1 |tee -a /Users/didi/Desktop/Daemon/daemon.txt
9.輸出所有進程
char *const ps_argv[]={"ps","-fe",NULL};
// execvp("ps", ps_argv);
10.查看某個文件權(quán)限
execle("ls","ls","-al","/Users/didi/Desktop/shell.sh",(char *)0);