SHELL

目录
  1.进程监控
  2.判断QQ是否运行
  3.查看某目录下的文件
  4.从第几列保存
  5.普通用户切换到root
  6.自动登录到远程服务器
  7.调用脚本文件
  8.保存ps结果
  9.输出所有进程
  10.查看某个文件权限

1.进程监控

MAIN_EXISTS=`sudo launchctl list | grep org.apple.main.getdates`

echo "$MAIN_EXISTS"

if [ -n "$MAIN_EXISTS" ]; then

echo "进程org.apple.main.getdates已开启,无需关心"

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.自动登录到远程服务器

#!/usr/bin/expect

set timeout 30

spawn ssh -l username 192.168.1.1

expect "password:"

send "ispass\r"

interact    

7.调用脚本文件

iOS 调用脚本
execlp("/Users/didi/Desktop/RELOAD/RELOAD/reload.sh",NULL);

8.保存ps结果

#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.查看某个文件权限

execle("ls","ls","-al","/Users/didi/Desktop/shell.sh",(char *)0);

你可能感兴趣的:(SHELL)