0

I have a script in 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' "\

My problem is that once I run this script on my server (GUI) and issue the w command on the same server from the CLI then I got the following output:

[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 ~]#

I don't want to display this from w, please help me to hide my script in the output from w.

1

Lets consider a simple script for example:

[09:37] [vhost0 ~] # cat script.sh
echo "sleeping..."; sleep 100.

I run it, chec second terminal and here is what I see:

[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

But then we modify the script:

[09:40] [vhost0 ~] # cat script.sh
secretcommand() { echo "sleeping..."; sleep 100; }

echo SECRET | secretcommand

Checking the 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

Sure, its not like we're completely hide your presence from view, but still, that's hiding your dirty secrets from your parents ;)

UPD

Here is how the updated script should look like:

#!/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
  • I am using this script but unable to run script [root@D ~]# cat co.sh #!/bin/bash export DISPLAY=:1 value=$(</root/path.txt) cd $value gnome-terminal \ secretcommand() { --tab -t "CTCLManager" -e " sh -c 'sleep 1s; ./startapp CTCLManager' "\; } secretcommand() { --tab -t "SMM" -e " sh -c 'sleep 10s; ./startapp SMM' "\; } [root@D ~]# Output: [root@D ~]$ co.sh /root/co.sh: -c: line 5: syntax error near unexpected token (' /root/co.sh: -c: line 5: secretcommand() { --tab -t "CTCLManager" -e " sh -c 'sleep 1s; ./startapp CTCLManager' "\; }' [root@D ~]$ – Enhance Technology Jun 14 at 4:12
  • 1
    Because you did it wrong. First: you made a function out of parameters rather that from full command. Second, you did not actually invoke the function anyway. And lastly, you did not do the trick with echo - without it the w will still show your command. I updated my answer for you. – deimos Jun 14 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.