Skip to content

Instantly share code, notes, and snippets.

@compor
Created February 25, 2013 15:19
Show Gist options
  • Select an option

  • Save compor/5030507 to your computer and use it in GitHub Desktop.

Select an option

Save compor/5030507 to your computer and use it in GitHub Desktop.
create multiple screen session for a specific function
#!/bin/bash
#
# it starts multiple screen session whose usual task is remote ssh over
# a line separated list of IP's
# session_name : the prefix of the name of the screen sessions
# script_name : implements the remote ssh code e.g. with python's paramiko
# input_file_prefix : the prefix of the files for the script to process
# iterations : the number of input files which is equivalent to the screen sessions to be spawned (indexing is zero-based)
#
if [ $# != 4 ] ; then
printf "usage: %s: session_name script_name input_file_prefix iterations\n" $0
exit 1
fi
SESSION=$1
SCRIPT=$2
INPUT=$3
NUMBER=$4
awk -v name=$SESSION -v script=$SCRIPT -v file=$INPUT -v times=$NUMBER '
BEGIN{
if( times <= 0 )
exit 2
for( i = 0; i < times; i++ ) {
strCommand = sprintf( "screen -S %s%02d -md ./%s %s%02d", name, i, script, file, i );
printf strCommand "\n"
system( strCommand );
}
}'
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment