Linux Blog

Sequences with seq

Filed under: Quick Linux Tutorials,Shell Script Sundays — TheLinuxBlog.com at 9:28 pm on Sunday, July 19, 2009

I’m going to keep this one short since time I’ve had a serious lack of time recently. If you need to free up some time by putting repetitive commands into loops, you can use the command seq.

Basically, you can use any generic loop such as the while or for loop. Here are two examples:

for i in `seq 1 10`; do echo $i; done;

seq 1 10 | while read i; do echo $i; done;

These both count and echo from 1 to ten. Replace the echo $i; with whatever it is you want to do. You can use sleep, to sleep for a number of seconds, and any other logic you wish here.

Screen Script, Part Deux

Filed under: Shell Script Sundays — TheLinuxBlog.com at 6:09 pm on Sunday, May 3, 2009

So, the last script for handling the screen didn’t quite work out as I had liked so I have stopped using it. Basically if you try to SCP something, it would flip out because there was no terminal. Also, if you were trying to do anything in X after logging in with SSH you would have to detach your screen session first, which could get annoying. I’ve came up with this snippet, its rather ugly but is intended to be run after you log in if you want to start a screen session. I’d like a solution that logs me in with this sort of dialog selection but also allows X and scp transfers to work if a selection is not made. Perhaps it could be done on a timer. Anyhow, here is the script:

screen -r $(dialog –stdout –menu Test 20 50 10 `echo $(screen -ls | grep \( | sed -e ‘s/\t/,/g’ | cut -d , -f 2- | awk -F ‘,’ ‘{print $1,$2}’ | awk -F ‘.’ ‘{print $1,$3}’ | cut -d \  -f 1,3)`)

It errors if no selection was made but that can be changed pretty easily by adding some if logic. Perhaps I’ll tweak it and repost, or perhaps I’ll find a better solution. Who knows.