5

The following command has been entered:

sleep 12h; nuke-russia

It was entered on one of the Debian's ttys. I would like to cancel the sleep without nuking anything. I don't want the nuke command to run for even for a single moment. I have the other five terminals available. What can I do?

4
  • 3
    Nuke it from orbit - it's the only way to be sure
    – Linker3000
    Jun 27, 2011 at 16:20
  • Is hitting the power off switch an option?
    – Mokubai
    Jun 27, 2011 at 17:02
  • @Mokubai: I omitted that option as trivial. I'm also not keen on losing my two-month uptime.
    – Mark
    Jun 27, 2011 at 17:14
  • Let's hope nobody with password 00000000 cuts and pastes this...
    – l0b0
    Feb 28, 2012 at 15:25

5 Answers 5

0

In future, try using && instead of ;
sleep X && echo bla pressing ctrl + C will stop sleep and will not echo bla

If it's feasible, you could rename the responsible binary . That way bash will not be able to execute nuke-russia since it will not exist.

Other solution would be to kill the responsible shell

EDIT:
How to find PID of responsible shell (which should its parent)
If pid of sleep 12h is 1234
find responsible shell with ps -o ppid= 1234
Then kill it with kill -9

1
  • I think the whole point of the exercise is that && was not used specifically to ensure nuke-russia is executed if the sleep command is killed. Otherwise, great suggested solutions. Jun 27, 2011 at 18:05
2
  1. Find nuke-russia
  2. Rename it old-nuke-russia
  3. Create a link in the same directory to ls called, ahem..., nuke-russia.

Let the sleeping command run as it wishes. You have 12 hours to find the person who ran the command and strangle them for trying to start a world war.

1
  • 1
    easiest solution. or just chmod 000 the file for a little while then end the command.
    – Sirex
    Feb 28, 2012 at 14:41
1

Apparently

kill -s SIGHUP [pid]

Should completely kill that terminal session and effectively hang up that session.

So as with other answers the command ps -ef | grep sleep should get you the pid you need to send the signal to.

-=EDIT=-

The kill flag -s tells the command that I am wanting to specify the signal to use, in my case SIGHUP.

To clarify why I have chosen to suggest the use of kill -s SIGHUP [pid] (or ppid as suggested by peth) I will enlist the help of Wikipedia which states:

On POSIX-compliant platforms, SIGHUP is a signal sent to a process when its controlling terminal is closed. (It was originally designed to notify the process of a serial line drop). SIGHUP is a symbolic constant defined in the header file signal.h.

...

With the decline of access via serial line, the meaning of SIGHUP has changed somewhat on modern systems, often meaning a controlling pseudo or virtual terminal has been closed.

I have found a good number of programs that, upon their terminal being killed, will themselves fully terminate and I believe that the bash shell (running the sleep command) would be no different in this case.

3
  • Isn't the PPID of sleep command the PID of responsible tty?
    – bbaja42
    Jun 28, 2011 at 6:27
  • 2
    Terminals don't have process IDs, bbaja42. peth is pointing out the important point that one needs to kill the shell to stop it running its next command.
    – JdeBP
    Jun 28, 2011 at 11:48
  • @JdeBP thanks for info, I didn't not know that. I still don't understand the flag -s?
    – bbaja42
    Jun 28, 2011 at 16:11
-1

Similar answer to Linker3000's - Log in as root from another terminal, and kill the tty process (On CentOS the process is named login, not sure about Debian).

3
  • No, that won't work. As peth has pointed out, to stop the shell from executing its next command, which it otherwise will simply do, one needs to kill the shell, not any login processes.
    – JdeBP
    Jun 28, 2011 at 11:51
  • Well it works for me (I replaced nuke-russia with shutdown)
    – jrb
    Jun 28, 2011 at 15:27
  • You killed the shell without realizing it or as a side-effect.
    – JdeBP
    Jun 28, 2011 at 16:13
-3

Login as root user on another terminal.

Find the nuke-russia script (or command) and rename it to something else, then...

[root@mysvr ~]# ps -ef | grep sleep
root      1362  1338  0 17:23 pts/0    00:00:00 sleep 12h
root      1393  1367  0 17:24 pts/1    00:00:00 grep sleep

Pick the right sleep command from the list (if more than one) and note its PID number - in my case, it's 1362

type command: kill -9 [PID] eg: kill -9 1362

5
  • Tried it, it still run nuke-russia after sleep is killed
    – bbaja42
    Jun 27, 2011 at 16:30
  • Hmm, tried it on my Fedora machine before I wrote it up and the sleep command dropped out with an error that the file or command could not be found.
    – Linker3000
    Jun 28, 2011 at 8:01
  • And the file or command that could not be found would be "nuke-russia". That is expected since you probably don't have nuke russia command. Try with echo "nuke-russia" instead.
    – bbaja42
    Jun 28, 2011 at 10:53
  • Appreciated - but the whole point was to stop the nuke command from running, which my solution does, albeit you get an error message.
    – Linker3000
    Jun 28, 2011 at 11:36
  • ??? you can an error message because you don't have nuke-russia , your solution is wrong
    – bbaja42
    Jun 28, 2011 at 16:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .