a couple of scripts for screen users

I am an avid user of the utility screen, it's my favorite window manager! Below is a couple of shell scripts for screen users.

- ns <hostname> - will start a new screen and ssh to the <hostname> provided.
- na <application> - will start a new screen and start the <application> provided.

Code:
#!/bin/bash

if [ $# = 1 ]; then
		# echo "number of arguments is $#"
		screen -t $1 ssh -o ServerAliveInterval=300 -o TCPKeepAlive=yes $1
	else
		echo "USAGE: `basename $0` <hostname>"
		echo "This will start a ssh session to a server in a new screen"
	fi
Code:
#!/bin/bash

if [ $# = 1 ]; then
		# echo "number of arguments is $#"
		screen -t $1 $1
	else
		echo "USAGE: `basename $0` <hostname>"
		echo "This will start an application on a new screen"
	fi
 
Nitpicky: you shouldn't create scripts beginning with #!/bin/bash (use #!/bin/sh instead) and you should return non-zero on error.
 
I'll correct it next time. I have to abmin Linux and FreeBSD machines at work and it's easier to just to simlink /bin/bash to where ever bash is. I should use "env" instead of simlinking, my bad.
 
Actually you can use #/bin/sh on _every_ Unix-System. You just need to make sure to not use any bashisms, so that your script can be portable.
 
lme@, I wish there was a utility that would tell you if you were using bashism's.:e
 
rbelk said:
lme@, I wish there was a utility that would tell you if you were using bashism's.:e

Like this? ;-)

$ grep '#!/bin/bash' $file && echo "AAAAAAAAAaaaaarrrrrrrrggggghhhhhh"
 
Following should work under any UNIX like system to show your current shell:
Code:
ps -p $$

Edit: I did not read above post, this command is about finding out your current shell ...
 
Let me rephrase my comment, I wish there was a utility that scans shell scripts for bashism's.
 
Vivek, an easier way to find the type of shell you are running is using shell=`echo $0` in the shell script, I have acually used that before.
 
rbelk said:
Vivek, an easier way to find the type of shell you are running is using shell=`echo $0` in the shell script, I have acually used that before.

nice, I wasn't aware of this tiny hack!

Let me rephrase my comment, I wish there was a utility that scans shell scripts for bashism's.

May be you can use something as follows:
Code:
#!/bin/sh
DIR=$@
BASHPATH=/bin/bash
[ $# -eq 0 ] && ( echo "Usage: $0 dir-nanme"; exit 1) 
for d in $DIR
do
	FILES=$(find $d -type f -print)
	for f in $FILES
	do
		grep "#!${BASHPATH}" $f > /dev/null 2>&1  && echo $f 
	done
done
 
rbelk said:
I am an avid user of the utility screen, it's my favorite window manager! Below is a couple of shell scripts for screen users.

- ns <hostname> - will start a new screen and ssh to the <hostname> provided.
- na <application> - will start a new screen and start the <application> provided.

Code:
#!/bin/bash

if [ $# = 1 ]; then
		# echo "number of arguments is $#"
		screen -t $1 ssh -o ServerAliveInterval=300 -o TCPKeepAlive=yes $1
	else
		echo "USAGE: `basename $0` <hostname>"
		echo "This will start a ssh session to a server in a new screen"
	fi
Code:
#!/bin/bash

if [ $# = 1 ]; then
		# echo "number of arguments is $#"
		screen -t $1 $1
	else
		echo "USAGE: `basename $0` <hostname>"
		echo "This will start an application on a new screen"
	fi

I am confused - is this to be invoked within screen or outside of it?
 
vivek said:
nice, I wasn't aware of this tiny hack!



May be you can use something as follows:
Code:
#!/bin/sh
DIR=$@
BASHPATH=/bin/bash
[..][/quote]

"#!/bin/bash" at the beginning of the script is not the only possible bashism, so I believe this is still not what rbelk wanted.

/bin/sh will tell you that the script uses bashisms by complaining because of syntax errors or not interpreting the script as expected. ;) Just use #!/bin/sh from now on.
 
Estrabd, these scripts are to be used only from inside screen. I start my screen session on my local box and the use "na elinks" to start elinks on a new screen. Also "ns system1" will start a ssh session to system1 on a new screen.

Do not use these from the regular command line, it will confuse you. I will add some error checking to make sure you are in a screen session before running them.
 
Back
Top