Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is it possible to run a command after a "pause" in linux desktop? For example:

#=========================================================
#NetworkManage Auto Connect:
chkconfig NetworkManager off
echo "service NetworkManager start" >> /etc/rc.d/rc.local
#=========================================================

I need to execute a command after networkmanager has connected successfully, and I think the best way to do this is by giving it an 8 second pause.

How can I execute something such as:

gedit test.txt

about 8 seconds after the command itself has been executed?

share|improve this question

migrated from stackoverflow.com May 31 '13 at 5:27

This question came from our site for professional and enthusiast programmers.

2 Answers 2

NetworkManager has a built-in feature: it can run scripts for you on network up and down events.

You have to place your scripts at: /etc/NetworkManager/dispatcher.d/

Every script will get two parameters from NetworkManager, the first one is what interface had the event and the second one is the event (up or down).

Example script:

#!/bin/bash

INTERFACE=$1 # The interface which is brought up or down
STATUS=$2 # The new state of the interface

echo interface $INTERFACE went $STATUS
share|improve this answer
    
i opened a new question about this. stackoverflow.com/questions/16848021/… –  Universal Name May 31 '13 at 0:49

Will the sleep command do what you need? Like this:

sleep 4 && echo 'hello there!'

(Waits four seconds, then prints a message)

EDIT: Or for your example,

sleep 8 && gedit test.txt
share|improve this answer
    
tested this sleep 8 && gedit test.txt out by adding it to the bottom of /etc/rc.d/rc.local for some reason it did not execute at all after rebooting. –  Universal Name May 30 '13 at 23:51
    
infact even "gedit test.txt" is not working in that startup file, so nothing is wrong with the command, perhaps this is for a different question ? –  Universal Name May 30 '13 at 23:55
    
Oh, I'm not an expert but I think you'd need to already have an open terminal to be able to run an editor. You could have rc.local open one like this, perhaps? bbs.archlinux.org/viewtopic.php?id=133065 but @user89709 has a good answer, in that it is probably better not to put a startup process to sleep for 8 seconds on every reboot. –  Don McCurdy May 31 '13 at 0:03
    
This might do it though: xterm -hold -e "sleep 8 && gedit test.txt" –  Don McCurdy May 31 '13 at 0:08
    
if i run in the desktop manually : sleep 10 && gedit test.txt it works, but in the rc.local file the only thing that works is gnome-terminal -e "gedit test.txt" with sleep it does not work. i tried both gnome-terminal -e "sleep 10 && gedit text.txt" as well as sleep 10 && gnome-terminal -e "gedit test.txt" –  Universal Name May 31 '13 at 2:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.