我在linux下有一个脚本:
#!/bin/bash
export DISPLAY=:1
value=$(</home/pace/Desktop/BODVersion.txt)
cd $value
gnome-terminal \
--tab -t "CTCLManager" -e " sh -c 'sleep 1s; ./startapp CTCLManager' "\
--tab -t "SMM" -e " sh -c 'sleep 10s; ./startapp SMM' "\
--tab -t "ClientCommunicator" -e " sh -c 'sleep 20s; ./startapp ClientCommunicator' "\
--tab -t "GATS" -e " sh -c 'sleep 30s; ./startapp GATS' "\
我的问题是,一旦我在服务器 (GUI) 上运行此脚本并w
从 CLI 在同一服务器上发出命令,就会得到以下输出:
[root@demo ~]# w
12:23:27 up 8:22, 10 users, load average: 4.12, 2.92, 1.75
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.0.100 11:43 0.00s 0.00s 0.00s w
pace pts/1 :1 12:16 6:39 2.38s 0.00s sh -c sleep 1s; ./startapp CTCLManager
pace pts/2 :1 12:16 6:39 0.05s 0.00s sh -c sleep 10s; ./startapp SMM
pace pts/3 :1 12:16 6:39 0.20s 0.00s sh -c sleep 20s; ./startapp ClientCommunicator
pace pts/5 :1 12:16 6:39 12:52 0.00s sh -c sleep 30s; ./startapp GATS
[root@demo ~]#
我不想在 中显示此内容w
,请帮助我在 的输出中隐藏我的脚本w
。
答案1
让我们考虑一个简单的脚本:
[09:37] [vhost0 ~] # cat script.sh
echo "sleeping..."; sleep 100.
我运行它,检查第二个终端,这是我看到的:
[09:37] [vhost0 ~] # w
09:36:42 up 17:20, 2 users, load average: 0.06, 0.03, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.56.1 Wed20 2.00s 0.07s 0.00s sleep 100
root pts/1 192.168.56.1 09:08 0.00s 0.09s 0.01s w
但接下来我们修改脚本:
[09:40] [vhost0 ~] # cat script.sh
secretcommand() { echo "sleeping..."; sleep 100; }
echo SECRET | secretcommand
检查w
...
[09:36] [vhost0 ~] # w
09:40:40 up 17:24, 3 users, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.56.1 Wed20 8.00s 0.10s 0.00s bash script.sh
root pts/1 192.168.56.1 09:08 0.00s 0.09s 0.00s w
当然,这并不是说我们完全隐藏了您的存在,但仍然向您的父母隐瞒了您的肮脏秘密;)
UPD
更新后的脚本应如下所示:
#!/bin/bash
export DISPLAY=:1
value=$(</home/pace/Desktop/BODVersion.txt)
cd $value
secretcommand() {
gnome-terminal \
--tab -t "CTCLManager" -e " sh -c 'sleep 1s; ./startapp CTCLManager' "\
--tab -t "SMM" -e " sh -c 'sleep 10s; ./startapp SMM' "\
--tab -t "ClientCommunicator" -e " sh -c 'sleep 20s; ./startapp ClientCommunicator' "\
--tab -t "GATS" -e " sh -c 'sleep 30s; ./startapp GATS' "\;
}
echo SECRET | secretcommand