| Author |
Message |
rcrsn51

Joined: 05 Sep 2006 Posts: 7744 Location: Stratford, Ontario
|
Posted: Sun 29 Aug 2010, 12:43 Post subject:
How to Make a Clickable Script |
|
You may have scripts that you use regularly, but must open a terminal window to run them. Here is a simple method for making a script clickable. You can then put a shortcut to the script on your desktop.
Just place the following three lines at the top of the script (without any blank lines):
| Code: | #!/bin/sh
tail -n +4 $0 > /tmp/script.txt
exec rxvt -e sh /tmp/script.txt |
To leave the terminal window open when the script is done, add this line to the end:
Here is an example. When I'm working with flash drives, I like to run the sync command regularly to ensure that data has been written out to the device. So I made a script called "mysync" and put it in /root/my-applications/bin. I then made a desktop shortcut by dragging the script onto the desktop. That way, I can see the sync command running and I know when it's done.
| Code: | #!/bin/sh
tail -n +4 $0 > /tmp/script.txt
exec rxvt -e sh /tmp/script.txt
echo Syncing...
sync |
Last edited by rcrsn51 on Sat 02 Feb 2013, 10:48; edited 5 times in total
|
|
Back to top
|
|
 |
abushcrafter

Joined: 30 Oct 2009 Posts: 1447 Location: England
|
Posted: Sun 29 Aug 2010, 17:46 Post subject:
|
|
Thanks.
_________________ adobe flash is rubbish!
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/
|
|
Back to top
|
|
 |
abushcrafter

Joined: 30 Oct 2009 Posts: 1447 Location: England
|
Posted: Tue 31 Aug 2010, 05:21 Post subject:
|
|
You need the 2 main commands to be on the same line with "&&" in-between. Other wise the exec command ends up in the tmp file. So it ends up in a loop where it keeps running more copy's of it self till it crashes your OS from using up all of your ram .
| Code: | | cat $0 | tail -n +4 > "/tmp/download_magatune_song-of-the-today_tmp.sh" && exec rxvt -e sh "/tmp/download_magatune_song-of-the-today_tmp.sh" |
I also added a rm command to delete the tmp file at the end of the script.
_________________ adobe flash is rubbish!
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/
|
|
Back to top
|
|
 |
rcrsn51

Joined: 05 Sep 2006 Posts: 7744 Location: Stratford, Ontario
|
Posted: Tue 31 Aug 2010, 05:40 Post subject:
|
|
Make sure that the first three lines of your script are as shown.
Then the "tail -n +4" copies everything starting at line 4 into the temp file.
|
|
Back to top
|
|
 |
abushcrafter

Joined: 30 Oct 2009 Posts: 1447 Location: England
|
Posted: Tue 31 Aug 2010, 06:11 Post subject:
|
|
| rcrsn51 wrote: | Make sure that the first three lines of your script are as shown.
Then the "tail -n +4" copies everything starting at line 4 into the temp file. | Arrr... I get it now. I had a new line after "#!/bin/sh".
_________________ adobe flash is rubbish!
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/
|
|
Back to top
|
|
 |
rcrsn51

Joined: 05 Sep 2006 Posts: 7744 Location: Stratford, Ontario
|
Posted: Tue 31 Aug 2010, 06:29 Post subject:
|
|
| abushcrafter wrote: | | I had a new line after "#!/bin/sh". |
That will do it.
Also, you don't need to delete the script afterward. The /tmp folder is automatically erased.
|
|
Back to top
|
|
 |
abushcrafter

Joined: 30 Oct 2009 Posts: 1447 Location: England
|
Posted: Tue 31 Aug 2010, 06:30 Post subject:
|
|
| rcrsn51 wrote: | | abushcrafter wrote: | | I had a new line after "#!/bin/sh". |
That will do it.
Also, you don't need to delete the script afterward. The /tmp folder is automatically erased. | Oh.
_________________ adobe flash is rubbish!
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/
|
|
Back to top
|
|
 |
steve_s

Joined: 26 May 2008 Posts: 1543 Location: Austin, TX, USA
|
Posted: Tue 31 Aug 2010, 07:28 Post subject:
|
|
Thanks for the script tips...keep 'em coming! this is very useful stuff and very appreciated...
|
|
Back to top
|
|
 |
piratesmack

Joined: 16 Sep 2009 Posts: 100
|
Posted: Tue 31 Aug 2010, 18:23 Post subject:
|
|
Yes, thanks for the tip.
I modified slightly so the script doesn't have to start at exactly 4 lines
| Code: |
#!/bin/sh
# figure out which line the script starts at
LINE=$(awk '/^START/ { print NR + 1 }' $0)
tail -n+$LINE $0 > /tmp/myscript.txt
exec rxvt -e sh /tmp/myscript.txt
START # script starts after this line
echo "Hello, world!"
read
|
|
|
Back to top
|
|
 |
|