Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

In my .screenrc file, I have this line to open one screen window:

screen -t "normal"

And this line to open another window and run top:

screen -t "top" top

Those work just fine so I wanted to immediately run df && ls -alh in a third window, so I placed this line into the .screenrc:

screen -t "df" df && ls -alh

The df window never appears so I thought the && may be the cause of the problem and tried it with just df.

screen -t "df" df

The df window still fails to appear.

Question: How can I run one command followed by another in the same screen window via screenrc? I'd like for it to behave exactly as it does in bash. Thanks for any advice.

share|improve this question

migrated from stackoverflow.com Apr 16 '12 at 1:48

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

up vote 2 down vote accepted

It probably appears, but disappears after it ran.

Try the following:

screen -t "df" bash -c 'df && sleep 50'

This will show the output of the df command for 50 seconds.

To have a useful df output I would recommend you to use watch:

screen -t "df" watch -n 10 df

This will runs df in every 10 seconds, so you'll have the actual status of your free disk space on that terminal.

share|improve this answer
1  
That works. How do you keep the window from going away once the commands execute? – user1200129 Apr 12 '12 at 15:50
    
@01100110 I've updated my answer – KARASZI István Apr 13 '12 at 8:10
    
This works, but when you reconnect to the screen and stop the df loop by pressing ctrl-c, the screen terminates. Any way to start the screen so the screen stays live even if the program started within stops? – 576i Jan 28 at 9:58

Your Answer

 
discard

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

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