Script file or batch file

Booting, installing, newbie
Post Reply
Message
Author
User avatar
cruzin
Posts: 176
Joined: Thu 30 Nov 2006, 07:12

Script file or batch file

#1 Post by cruzin »

Hello, I did a search for script and did not find much on it that would help me to make one. I have a notebook, I take it with me sometimes while working away. Its a thinkpad t21 256 ram, 20 gig hdd. I do NOT have windoz or any other systems on the t21, I use puppy 2.14 from cd and not live cd as my t21 does not have a burner. I have a netgear wireless card that I use for hot spots. I have no problem getting on line with it wireless using modprobe, ifconfig and using the RutilT gaget to find and connect to networks. I have not been able to have it save the wireless profiles.
Can I make a script file or batch file and place it on my desktop to run Modprobe and ifconfig at the click of a icon? If so can someone explain to me how to make it and where in puppy to place it? thanks

Bruce B

#2 Post by Bruce B »

Where to place it?

I put my scripts in /root/bin, this way they don't get lost

I have to make the directory and then put /root/bin in the search path. I do this by editing /etc/profile and add the directory to the search path

How to make the script

Convention has us do the first line like this:
#!/bin/sh

A simple script would involve entering your commands, keeping in mind they will be executed from top to bottom of file.

The script must have the execute attribute, this can be accomplished by this command

# chmod 755 myscriptname

Example

Code: Select all

#!/bin/sh
# this simple script mounts hdc1 formatted as ext3 at /mnt/hdc1
# then displays top level files and directories
mount -t ext3 /dev/hdc1 /mnt/hdc1
ls /mnt/hdc1
Placing shortcut on desktop

Open ROX-Filer, find the script, drag and drop to desktop, name as you please, find an appropriate icon for it.

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#3 Post by zigbert »

here's my script to connect my wireless usb-device.
I have made some comments for you (#comments)

Code: Select all

#!/bin/bash
TMP=`lsmod | grep "rt73"` #check if module rf73 is loaded (driver for my wifi)
if [ -n $TMP ]; then #if not...
	modprobe rt73 #...load
fi
ifconfig rausb0 up #activate wifi device
sleep 1 #wait 1 second
iwconfig rausb0 essid default mode Managed #connect to the open net called 'default'
sleep 1
rm -f /etc/dhcpc/dhcpcd-*.pid #remove old configfile

PS=`ps`
TMP= `echo $PS | grep "dhcpcd"` #check if dhchcd is running (get dynamic ip-adress
if test -n $TMP; then #if not...
	dhcpcd rausb0 #...do
fi
TMP= `echo $PS | grep "rutilt"`
if test -n $TMP; then
	rutilt -t &
fi
TMP= `echo $PS | grep "seamonkey"`
if test -n $TMP; then
	mozilla
fi
Good luck

Sigmund

User avatar
cruzin
Posts: 176
Joined: Thu 30 Nov 2006, 07:12

my attempt

#4 Post by cruzin »

I went to dir bin and right or left clicked on no icon and choose (new file) and found that It listed (scritp) so I choose that and made a script file I found that when I choose new script that it opened up with the line opened up the abiword and #!/bin/sh so I added modprobe ath_pci and also ifconfig ath0 up which is the commands I use in console to load up the netgear card and make it active. I saved it and linked it to the desktop and it did not work then I tried just making a text file and tried it and it still did not work. Im looking over both replies more to see if I (newbie) can make sense of it. thanks for the help. Ill go through and change what I think I should and try it. this is what I have so far. That did not work..
#!/bin/sh
#modprobe ath_pci
#ifconfig ath0 up

User avatar
cruzin
Posts: 176
Joined: Thu 30 Nov 2006, 07:12

Re: my attempt

#5 Post by cruzin »

cruzin wrote:I went to dir bin and right or left clicked on no icon and choose (new file) and found that It listed (scritp) so I choose that and made a script file I found that when I choose new script that it opened up with the line opened up the abiword and #!/bin/sh so I added modprobe ath_pci and also ifconfig ath0 up which is the commands I use in console to load up the netgear card and make it active. I saved it and linked it to the desktop and it did not work then I tried just making a text file and tried it and it still did not work. Im looking over both replies more to see if I (newbie) can make sense of it. thanks for the help. Ill go through and change what I think I should and try it. this is what I have so far. That did not work..
#!/bin/sh
#modprobe ath_pci
#ifconfig ath0 up
I tried this edited file and did the execute afterwords and it told me no such device

#!/bin/sh
#!/bin/bash
TMP=`lsmod | grep "ath_pci"` #check if module ath0 is loaded (driver for my wifi)
if [ -n $TMP ]; then #if not...
modprobe ath_pci #...load
fi
ifconfig ath0 up #activate wifi device
sleep 1 #wait 1 second

as I do not know what lsmod | grep means I dont know if that is the problem..

above I listed what I do in the console to get my wireless card working
modprobe ath_pci
ifconfig ath0 up

then I get the wireless working and go to Rutil gaget

any more suggestions as you look what Ive tried? thanks again

User avatar
cruzin
Posts: 176
Joined: Thu 30 Nov 2006, 07:12

#6 Post by cruzin »

Bruce B wrote:Where to place it?

I put my scripts in /root/bin, this way they don't get lost

I have to make the directory and then put /root/bin in the search path. I do this by editing /etc/profile and add the directory to the search path

How to make the script

Convention has us do the first line like this:
#!/bin/sh

A simple script would involve entering your commands, keeping in mind they will be executed from top to bottom of file.

The script must have the execute attribute, this can be accomplished by this command

# chmod 755 myscriptname

Example

Code: Select all

#!/bin/sh
# this simple script mounts hdc1 formatted as ext3 at /mnt/hdc1
# then displays top level files and directories
mount -t ext3 /dev/hdc1 /mnt/hdc1
ls /mnt/hdc1
Placing shortcut on desktop

Open ROX-Filer, find the script, drag and drop to desktop, name as you please, find an appropriate icon for it.
When you said I need the chmod 755 to make it a run file is that the sme as clicking on the execute at the top of the file? and do I need the # at the beggining of each line? I always thought that when you added a # at the beggining of a line that then it was just comments and not commands. That may be from dos not sure. thanks

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#7 Post by sunburnt »

Yes, a # is a comment, except for the script specifier at the start of the file.
The # you see at the start of the line is Puppy's command prompt.

The normal place to put stuff like this is: /root/my-applications/bin
It's in the path already so there's no need to change the path.

I myself tend to like short dir. names like: /apps, /docs, etc.

User avatar
Sit Heel Speak
Posts: 2595
Joined: Fri 31 Mar 2006, 03:22
Location: downwind

#8 Post by Sit Heel Speak »

cruzin wrote:When you said I need the chmod 755 to make it a run file is that the sme as clicking on the execute at the top of the file?
No. Open Rox, navigate to wherever you have placed your script, right-click-on-white-space, Window-->Open Terminal Here, this will open an console window at the bash prompt. Now execute the chmod command as a command line, e.g.

# chmod 755 myscriptname

(don't type the "#", that's the prompt)

Now your script will execute.

User avatar
trapster
Posts: 2117
Joined: Mon 28 Nov 2005, 23:14
Location: Maine, USA
Contact:

#9 Post by trapster »

To make your file executable, right click on it and choose "permissions" when the window pops up, click yes if it shows "a+x (make executable)".
trapster
Maine, USA

Asus eeepc 1005HA PU1X-BK
Frugal install: Slacko
Currently using full install: DebianDog

User avatar
cruzin
Posts: 176
Joined: Thu 30 Nov 2006, 07:12

scritp file

#10 Post by cruzin »

Hi, thanks for all the suggestions
I have not been able to make it work as of yet.

This is what Ive done.

I went to the /bin folder, created a file called wireless, the file reads

#/bin/sh
modprobe ath_pci
ifconfig ath0 up

thats all I wrote I saved it and then went to the /bin folder and right clicked in the white and opened window and typed the chdmod 755 wireless which is what I named the file. closed the window. I deleted the icon I had on the desktop and re draged the new one over to the desktop , I then restarted the computer and clicked on the desktop icon and nothing happened. I went to my consol window to check if the ifconfig had anything about my ath0 being up and it did not list it. So I know that modprobe did not work.

Got a couple questions.
In the first line of the file

#/bin/sh (what does the letters /sh mean?) is sh the file name? should it read like this (#/bin/wireless)? being wireless is my file name?

and if starting up my pcmcia wireless card I always go to the console and type modprobe ath_pci enter
then I type ifconfig ath) up is this all I need to make the script

and to make sure ive placed it in the right place it located in
/bin

How does this look and sound? thanks again for the help.

User avatar
cruzin
Posts: 176
Joined: Thu 30 Nov 2006, 07:12

working now

#11 Post by cruzin »

Thanks all for the help. its working now.

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#12 Post by zigbert »

#/bin/sh (what does the letters /sh mean?)

It tell system to use /bin/sh to run this script. You have made a shell-script (sh). - Congratulations. They are very useful, and Puppy is full of them.

Post Reply