Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you start Unix screen command with a command?

Tags:

According to the docs for the Unix "screen" command, you can configure it in .screenrc to start with a bunch of default screens, each running a command that you specify.

Here's my cofig:

# Default screens screen -t "shell_0"  1 screen -t "autotest" 2 cd ~/project/contactdb ; autotest 

It will not run the autotest command. That window where I'm trying to run autotest just closes instantly when I start screen.

I also tried it with just...

screen -t "autotest" 2 cd ~/project/contactdb 

Same result.

I also tried...

screen -t "autotest" 2 ls 

Same result there too.

What's the secret to getting it to run a command in a given screen on startup?

like image 593
Ethan Avatar asked Feb 12 '09 22:02

Ethan


People also ask

How do I run a command in screen mode in Linux?

Begin by logging in to the server and starting the screen session via the command line. Next, type Ctrl-a to enter the command mode.

What is screen command in Unix?

screen command in Linux provides the ability to launch and use multiple shell sessions from a single ssh session. When a process is started with 'screen', the process can be detached from session & then can reattach the session at a later time.


2 Answers

Your program is being run (well, except the cd), it's just that it's being run without a parent shell, so as soon as it completes, it exits and you're done.

You could do:

screen -t "autotest" 2 bash -c 'cd ~/project/contactdb ; autotest' 

Spawns two shells, but life will probably go on.

like image 137
chaos Avatar answered Oct 31 '22 23:10

chaos


Try this:

$ screen -S 'tailf messages' -d -m tailf /var/log/messages 

Then later you can do:

$ screen -ls 1234.tailf messages 

Followed by:

$screen -r 1234 
like image 34
sodamnmad Avatar answered Oct 31 '22 22:10

sodamnmad