Find the answer to your Linux question:
Results 1 to 10 of 10
Hey there I have come across a situation where I need a command to execute by itself after a period of time. Say for a simple example clear the screen ...
  1. #1
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493

    executing a command after a period of time

    Hey there
    I have come across a situation where I need a command to execute by itself after a period of time. Say for a simple example clear the screen after every 5 min ( as simple as that , but that's not wat i want to do lolz) . How do i accomplish that???
    Only if I could understand the man pages
    Registered Linux user #492640
    OS: RHEL4,5 ,RH 9,Ubuntu

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Shedule commands for single execution: man at; man atd

    Periodic execution: man crontab
    Debian GNU/Linux -- You know you want it.

  3. #3
    Banned
    Join Date
    Jun 2007
    Posts
    4
    What about a cron job? Those are rather easy to find info on setting up.... Google it !

  4. #4
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    If you provide more details I might be able to give a more adequate response.

    However, in bash you could do this with a simple loop, for example:

    Code:
    while true; do echo foo; sleep 2; done

  5. #5
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493
    ok like i want to see the ppl who are logged on the tty after every five min.
    Only if I could understand the man pages
    Registered Linux user #492640
    OS: RHEL4,5 ,RH 9,Ubuntu

  6. #6
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Then you could do something like this on a terminal:

    Code:
    while true; do users; sleep 2; done
    Or if you preffer a fancy notification you could use:

    Code:
    while true; do notify-send "$(users)"; sleep 5m; done
    Or

    Code:
    while true; do users|osd_cat; sleep 5m; done

  7. #7
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493
    But every time i ll have to write the code manually. Is'nt there a way by which I can just tell bash to execute a script after some time.
    Only if I could understand the man pages
    Registered Linux user #492640
    OS: RHEL4,5 ,RH 9,Ubuntu

  8. #8
    Just Joined! rjayavrp's Avatar
    Join Date
    Apr 2009
    Location
    Incredible India
    Posts
    42

    Thumbs up

    try this.....

    at now + 5 minutes < $HOME/listofcommands.txt

    i googled it,, and i have to test.

    i hope this will help u.

  9. #9
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by vickey_20 View Post
    But every time i ll have to write the code manually. Is'nt there a way by which I can just tell bash to execute a script after some time.
    That depends on your desktop and how do you start X. Most desktops have an autostart features, standalone wm's do have a config file which can usually launch whatever you want at start (some of them might have a graphical tool to configure this).

    In kde you can drop any script you want to run at startup on ~/.kde/Autostart (at least in 3.x, I don't know about 4.x). No idea on how gnome do this, but I guess the place to look into is the session manager.

    If you start X by hand with the startx command then you can put whatever you want to run in xinitrc, make sure you append an & at the end of the line so the command is backgrounded.

    About the "at" command, it won't work for this purpose. "at" just schedules something to run at a later time, but it won't re-run it at regular intervals. At least not that I know of (though admittedly I haven't ever used it. I consider it to be useless, completely useless. You can just do "sleep 5m; whatever_command" instead.

  10. #10
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493
    how to do that in red hat 5
    Only if I could understand the man pages
    Registered Linux user #492640
    OS: RHEL4,5 ,RH 9,Ubuntu

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...