Help - Search - Members - Calendar
Full Version: Why Don't My Scripts Run?
Linuxhelp > Support > Technical Support
cagey cretin
In my trials of trying to get a mailserver working, I have had to do clean installs of Redhat 9 enough times that I decided to write a few scripts to copy data files /folders from a CD, create directories, chmod & chown other directories.

These scripts worked fine when I wrote them (I put them in the 'scripts' folder), and then I burned them onto a data CD so that I wouldn't have to write them each time I installed. However, when I tried them on a fresh install (run from the 'scripts' folder), nothing happened. unsure.gif I mean, the computer looked like it had HD activity, the CD rom had activity, and then nothing. dry.gif

This is really frustrating. It seems so counter-productive to not really know if something is going to work or not, and really defeats the whole purpose of trying to automate processes.
I use scripts to do many things ... so scripts work biggrin.gif

The problem with scripts is this:

They do exactly what we TELL them to do ... not what we WANT them to do wink.gif
Some pointers (that I learned the hard way) are:

1. Either include the full path to your executable (/bin/ls instead of ls, for example) ... or include a PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin near the top of the file.

2. Always include a pointer as the first line of the file that points to the correct shell to run the program:



3. Make sure to set you environment variables in the script (especially if running from a cron ... root runs all crons and in a shell that DOESN'T have root's envronment. For example, if you want root's environment (in a bash script) then use the command:

source /root/.bash_profile

in the script.
cagey cretin
Thanks HughesJR. I tried your suggestion, but with no joy.

source /root/.bash_profile

It seems so illogical that the script that I wrote and tested (yeah, it worked fine) won't work after a new clean install. I swear to God I think people went out of their way to obfuscate how to set up a linux system!!!! (Not you, Not you!!!) It makes zero sense to me; I cannot see how it shouldn't have worked when it did earlier!!!!! GD it I hate this ####!!!!

if you post your script(s) I'll be glad to take a look at them and see if I can help.
cagey cretin

source /root/.bash_profile
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin near
cp -R /mnt/cdrom/docs  /root/.gnome-desktop
cp -R /mnt/cdrom/Qmail /root/.gnome-desktop
cp -R /mnt/cdrom/web /root/.gnome-desktop
cp -R /mnt/cdrom/conf /root/.gnome-desktop
cp -R /mnt/cdrom/scripts /root/.gnome-desktop
cp -R /mnt/cdrom/index.html /root/.gnome-desktop
cp /root/.gnome-desktop/scripts/SCRIPT_3_NEW_USERS /root/.gnome2/nautilus-scripts
cp /root/.gnome-desktop/scripts/SCRIPT_Services_HTTPD_VSFTPD /root/.gnome2/nautilus-scripts
I don't see anything wrong with the scripts ... was your CDROM mounted?
as a side note ... add this to the top of the script (between PATH and the first copy statement) and it will mount the CD if it is in the drive but not mounted:

mounted=`mount | grep cdrom`
if [ "$mounted"x == "x" ]; then
 #not mounted
  mount /dev/cdrom

{BTW, the ` is the key under ~ (to the left of the number 1) and not a single quote...items inside a `` are run and the result placed in the script}

another potential issue is that the desktop location is changed in gnome 2.4 ... it is no longer in .gnome_desktop, but at Desktop in the user's home directory. RedHat 9 has gnome 2.2 but there are places that you can upgrade to 2.4 ... the command:

rpm -q gnome-desktop

should give you your version if you aren't sure which you have...
cagey cretin
I really appreciate your time HughesJr. Thank you. smile.gif

The CD was mounted. I ran the script again and there is no activity at all. None whatsoever. I put in the 'mount CD ROM' code you provided, but there is still no activity. There must be something not set up right with Redhat 9 on my PC, so I am just going to forget it and cut and paste the text in a terminal screen.

Thank you again, and warmest regards,

cagey cretin
Thanks for trying Hughesjr. I wanted to give you closure (in that your info was right, but that I had bad dope on this end).

Let it be known that not any text editor within linux can create a script file. I opened up my script in vi and found extra characters at the end of each line that Redhats GNU gedit put there. I spent $50 for a big yellow 'Redhat 9 Bible' published by Hungry Minds. I swear, I own 5 or 6 books from them, and they have misleading information in all of them. They told me that any text editor will do just fine.


This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2018 Invision Power Services, Inc.