Operating System - HP-UX
1834178 Members
2510 Online
110064 Solutions
New Discussion

unusual problem with shell scripts

 
SOLVED
Go to solution
amonamon
Regular Advisor

unusual problem with shell scripts

helloo..

On my solaris I have 2 scripts...one is very simple just init 6

while the other is more complex..

both scripts work just fine but I have some aplication done on my remote windows and I can not execute init 6 script...but other scripts can be executed..any ides??
21 REPLIES 21
Peter Godron
Honored Contributor

Re: unusual problem with shell scripts

Hi,
can you please confirm/clarify:
1. These scripts are on a Solaris platform
2. If they are on a Solaris platform, why do you mention remote windows.
3. You say both scripts work fine, but then that you can not execute the init 6 script.


For point 3.: Have you checked the execute permissions with 'ls -l'
amonamon
Regular Advisor

Re: unusual problem with shell scripts

right i was confusing..
there are 2 ways to reach those scripts both from windows machine:

1. from emulator like putty both scripts work perfect i can restart machine..

2. using php and telenet class I can execute one script but script with init 6 can not be executed..

PHP code is OK I know that...and in all ways I am root.
Peter Nikitka
Honored Contributor

Re: unusual problem with shell scripts

Hi,

I'm shure you can tell us the error message, wen you try to execute that script.
'init 6' is a call for reboot, so:
- what is the name of the script calling 'init 6'
- what else is found in that script?


mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Ralph Grothe
Honored Contributor

Re: unusual problem with shell scripts

Since you mentioned PHP,
did I get it right that you want from your remote Windows PC (from a browser?) reboot your Solaris server by an init 6 through some sort of CGI script?
So is there a webserver which is supposed to execute the PHP involved?
For security reasons you wouldn't want the webserver on the Solaris box being run as root.
Madness, thy name is system administration
amonamon
Regular Advisor

Re: unusual problem with shell scripts

ok I have script restartNode:

#!/bin/ksh


responce="US"
if [ $responce == "US" ]; then
# echo "cao"
# ./restart214
init 6
#shutdown -i6 -g0 -y
echo "has not been created">>kFILE
else
echo "$dir has not been created"
fi


if I execute it via putty it restarts machine..and works perfect..
but with PHP I just can not execute this script all others can be executed..
to be more precised:

script

#!/bin/ksh


responce="US"
if [ $responce == "US" ]; then
# echo "cao"
# ./restart214
# init 6
#shutdown -i6 -g0 -y
echo "has not been created">>kFILE
else
echo "$dir has not been created"
fi

can be executed via PHP
so if I put # before init 6 it works even via PHP(telnet from windows) but if I remove # it does not work..

strange...
Peter Nikitka
Honored Contributor

Re: unusual problem with shell scripts

Hi,

- try to catch the error
- call init with pathname


#!/bin/ksh
responce="US"

exec 2>/tmp/shutt.err

if [ $responce == "US" ]; then
# echo "cao"
# ./restart214
/usr/sbin/init 6
#shutdown -i6 -g0 -y
echo "has not been created">>kFILE
else
echo "$dir has not been created"
fi

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
amonamon
Regular Advisor

Re: unusual problem with shell scripts

I tryed to catch errors..it creates error file but no errors inside that file..

Peter Nikitka
Honored Contributor

Re: unusual problem with shell scripts

Hi,

modify script to get traces:

#!/usr/bin/ksh -x
exec 2>/tmp/shutt.err
responce="US"

if [ $responce == "US" ]; then
echo "ciao"
# ./restart214
/usr/sbin/init 6
#shutdown -i6 -g0 -y
echo "has not been created">>kFILE
else
echo "$dir has not been created"
fi

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
amonamon
Regular Advisor

Re: unusual problem with shell scripts

Peter I did that I get empty file errors.err
Peter Nikitka
Honored Contributor

Re: unusual problem with shell scripts

Hi,

if you really have added the 1st+2nd line of the script to

#!/usr/bin/ksh -x
exec 2>/tmp/shutt.err

and do not get anything then your script must terminate before the next statement. This example

cat /tmp/b
#!/usr/bin/ksh -x
exec 2>/tmp/tstout
a=5

produces this output file:
cat /tmp/tout
+ a=5

Buildup a testscript like

#!/usr/bin/ksh -x
exec 2>/tmp/tstout
echo start >/dev/stderr
/usr/sbin/init 6
echo $?


mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Marvin Strong
Honored Contributor

Re: unusual problem with shell scripts

I thought from left field.
Does init require a valid session to be used? I know it uses pam for session management.



amonamon
Regular Advisor

Re: unusual problem with shell scripts

hello

I tried what peter told..I got in my shutt.err this:

+ echo has not been created
+ 1>> /opt/tomcat/logs/meme/crFILE
+ init 6

and I executed this:

#!/bin/ksh -x
exec 2>/opt/tomcat/logs/meme/shutt.err

echo "has not been created">>/opt/tomcat/logs/meme/crFILE
init 6


and again solaris is not being restarted..
but again if I execute this script from command line solaris restarts...

can anyone figure what might be my problem...:)
Peter Nikitka
Honored Contributor

Re: unusual problem with shell scripts

Hi,

as I and you see, you
- do not have entered the full pathname /usr/sbin/init 6
in your script, but only 'init 6'
- you do not have setup the check for the exit-status of that command
- a command 'init 6' gets executed

So try EXACTLY that script and tell us the resulting output.

#!/usr/bin/ksh -x
exec 2>/tmp/tstout
echo start >/dev/stderr
/usr/sbin/init 6
echo $?

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
amonamon
Regular Advisor

Re: unusual problem with shell scripts

Hello...output is:
cat tstout:

+ echo start
+ 1> /dev/stderr
start
+ /usr/sbin/init 6


but still..solaris stays not restarted..:(

Peter Nikitka
Honored Contributor

Re: unusual problem with shell scripts

Hi,


we see that /usr/sbin/init is called but does not come back again to your script, since no
+ echo NN
is seen in the outout file.

Did the command finish or does it hang at that point?

Best would be not to call a reboot in that way.
Perhaps let an at-job do the work, like

...
echo /usr/sbin/reboot | at now +1 min
...

mfG Peter

PS: My general opinion in case of rebooting is still "do it only when it's necessary and not on a regular base".
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
amonamon
Regular Advisor

Re: unusual problem with shell scripts

well..I know but I need restart..so my question is considering that I am new in UNIX can I safely use that reboot command...is there difference between it and init 6??

and just another point..considerin that I am doing all this from my windows mach.on it it is apache and PHP is there maybe some restriction on my apache to prevent restart..I mean is it possible that my apache does not allow remote telnet restart ...I doubt..but..who knows..
Once again can U explain me last command reboot and can I use it..THANKS a lot..

amonamon
Regular Advisor

Re: unusual problem with shell scripts

echo /usr/sbin/reboot | at now +1 min

can I just enter that in script..together with this: at now +1 min??

Do U think it is safe enough..sorryy again but I am new in solaris..but would love very much to learn..
Peter Godron
Honored Contributor

Re: unusual problem with shell scripts

Reboot performs a normal orderly reboot, whereas init 6 reboot by terminating all running processes, unmounting all filesystems and rebooting to initdefault in /etc/inittab.
So the orderly shutdown, for example of oracle does not take place with init 6.
See man init and man inittab
amonamon
Regular Advisor

Re: unusual problem with shell scripts

and one more thing...what would be diff between:

-> shutdown â i6 â g0 -y

-> init 6

-> echo /usr/sbin/reboot | at now +1 min


those "3 restarts"...thanks for explanation..
Peter Nikitka
Honored Contributor
Solution

Re: unusual problem with shell scripts

Hi,

the line

echo /usr/sbin/reboot | at now +1 min

should be the substitute for

/usr/sbin/init 6

in your script. The at-job submitted will launch a reboot one minute after being scheduled.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
amonamon
Regular Advisor

Re: unusual problem with shell scripts

Peter I do not know where is an issue..but commnad

echo /usr/sbin/reboot | at now +1 min

worked for me...init 6 did not work but I could restart my system with this command..I just changed my shell script and put that in it...

regards...