Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 22 Oct 2014, 18:38
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
How to Make a Clickable Script
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [9 Posts]  
Author Message
rcrsn51


Joined: 05 Sep 2006
Posts: 9202
Location: Stratford, Ontario

PostPosted: 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:
Code:
read

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
View user's profile Send private message 
abushcrafter


Joined: 30 Oct 2009
Posts: 1447
Location: England

PostPosted: 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
View user's profile Send private message Visit poster's website 
abushcrafter


Joined: 30 Oct 2009
Posts: 1447
Location: England

PostPosted: 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 Sad.
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
View user's profile Send private message Visit poster's website 
rcrsn51


Joined: 05 Sep 2006
Posts: 9202
Location: Stratford, Ontario

PostPosted: 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
View user's profile Send private message 
abushcrafter


Joined: 30 Oct 2009
Posts: 1447
Location: England

PostPosted: 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
View user's profile Send private message Visit poster's website 
rcrsn51


Joined: 05 Sep 2006
Posts: 9202
Location: Stratford, Ontario

PostPosted: 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
View user's profile Send private message 
abushcrafter


Joined: 30 Oct 2009
Posts: 1447
Location: England

PostPosted: 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
View user's profile Send private message Visit poster's website 
steve_s


Joined: 26 May 2008
Posts: 1545
Location: Austin, TX, USA

PostPosted: 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
View user's profile Send private message Visit poster's website 
piratesmack


Joined: 16 Sep 2009
Posts: 100

PostPosted: 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
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [9 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0599s ][ Queries: 12 (0.0045s) ][ GZIP on ]