Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have six shell scripts I start when I log in. The shell scripts kick off Python scripts which go out and scrape various things from the net like news headlines, weather info etc., which I add to my desktop via conky.

Problem is starting all of these shell scripts each time is a real pain.

I have looked for and tried some things but nothing seems to work.

Can someone here shed some light on the best way to do this pls. By the way I can't combine the shell scripts in a single file because they all 'sleep' for a different duration after the initial command is applied.


-- Edit (adding the following comments) --

All of the scripts have the following format:


while true; do
    python /home/scott/ > /home/scott/debka.txt
    sleep 120

Could that be added to the profile? I need the sleep aspect to it. I am running KDE 4.9.

share|improve this question

migrated from Aug 25 '12 at 11:00

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

Do you use a window manager? Which one? – choroba Aug 25 '12 at 0:59
What is the 'pain'? – New Alexandria Aug 25 '12 at 1:34
Well the pain is having to open up a terminal, type '', ctrl-t, and do this again and again. And my shell script list keeps growing, 7 now. :( – Scott Richardson Aug 25 '12 at 1:52
I think you should take the 2 parts of my answer and apply it in the locations NormanRamsey indicates. – New Alexandria Aug 25 '12 at 16:32
I was curious, too, for an explicit example - so I decided to build one. I'll probably use this myself next time. – New Alexandria Aug 25 '12 at 17:28

If you're "adding to your desktop" you have a window manager running, and if you are using bash it's probably Linux. In that case you're probably best off launching your scripts into the background from an Xsession file, either ~/.Xsession or /etc/X11/Xsession or a variant. For more info try

man 5 Xsession
man 1 xinit
share|improve this answer
While I and Leffler presented general purpose answers, this answer has the most domain-specific information. – New Alexandria Aug 25 '12 at 16:30

One possibility is to add the appropriate invocations to your .bash_profile or .profile file. When you run them manually, do you add an & at the end to run them in background? If so, do that in your profile too.

The main issue here is 'what happens if you've already run a login shell'. Do the 6 scripts behave sanely if there's another copy already running? Do they bother to detect that there's another copy already running.

If you're logging in at a GUI desktop, then there are ways to run programs when the desktop starts; use it to run the scripts that you're trying to deal with. For more accurate instructions (from other people), provide more information about your environment.

share|improve this answer
Hi, thanks for the reply. Well to start I am running KDE 4.9, recently moved to this from Ubuntu 12.04. I was doing the same thing on Ubuntu though. – Scott Richardson Aug 25 '12 at 1:48
Look to the Xsession suggestion by Mr Ramsey. – Jonathan Leffler Aug 25 '12 at 1:56

You can use this basic strategy:

  • have scripts start by creating pid files as Make the scripts abort if for their pid file exists
  • have scripts run in the background

When you invoke from your .bash_profile (or similar) then the pid files will prevent .bashrc from winding up more processes for each new shell.

Per NormanRamsey, you will add to the XSession (or other window manager):

# Web Scrapers

Consider writing bash functions. You could have a file

pid_path = "~/.X-scrapers/"
suff = '.pid'

function pidfile_create(invoker) {
  if [ ! -e $pid_path$invoker$suff ];
    # make it
    echo $$ > $invoker$suff
    # alert it existance
    cat $pid_path$invoker$suff
function pidfile_destroy(invoker) {
  rm $pid_path$invoker$suff
  if [ -e $pid_path$invoker$suff ];
    echo "$pid_path$invoker$suff could not be destroyed properly"

then on line 2 of each of your scrapers (e.g. This will prevent the script for executing if a scraper is already running.

if [ pidfile_create($0) ]

at the end of each scraper, put


You could have other tradeoffs, but this sounds reasonable for what you describe.

share|improve this answer

You must log in to answer this question.