Windows7 script execution puzzle

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 12 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Darkstar
Posts: 2
Last visit: Fri Feb 17, 2012 4:29 pm

Windows7 script execution puzzle

Post by Darkstar »

Hello - I am new to this forum, found it by Google, and hopefully I am not asking a question that has already been answered, and hopefully this is a good forum to ask. (no joy yet in finding any solutions to this problem I am having....) I have a puzzling problem with a .cmd script, running on a Windows 7 system, which I have written to shutdown a linux computer attached to a common UPS. Within this script I am executing a call to a utility, called plink, to send a command
to the linux system to shut it down -

(plink.exe -v -ssh -P 622 -l root -pw myPassword 192.168.2.100 shutdown
-h now) >> c:TempplinkLog.txt 2>&1
and as you can see I am also redirecting stdout and stderr to a log
file. (and don't be confused about the port number being 622, this is a
security step we use to "hide" the ssh ports on our systems, and the
linux system port forwards it to it's standard ssh port 22)
If I execute this .cmd file directly, either from a command shell
window, or by double clicking on the file's icon, it works! But here is
the problem. I have a Windows service, supplied by the UPS manufacture, that monitors the UPS and if the UPS
gets low on battery power, it has been configured to call this script, which is suppose to
shutdown my linux system. And when it does, it fails. The redirected output to the log file does
not reveal a lot of helpful information -

Looking up host "192.168.2.100"
Connecting to 192.168.2.100 port 622
Failed to connect to 192.168.2.100: Unknown network error
Unable to open connection:
Unknown network error

I have configured the Windows firewall to allow any program an outgoing
connection on port 622. This may be a script security/permissions
problem of some kind but I have been fooling around with those sort of
settings and still no joy. I also know that when this script is called
from the window's service, it is not inheriting any of the system
environment variables. Therefore, part of this script sets the PATH environment
variable, and that much is working since plink is found and is called. I don't
know what, if any, other Windows environment variables may be necessary
for plink to connect successfully to my linux system and I am not sure if there is a way to "restore" all the system environment settings so that they are available within the script?. I
don't know if this is a plink or ssh problem per say, a firewall issue, some kind of permissions issue, or missing environment variables, but I have spent a lot of time exploring all these possibilities and am running
out of ideas. So thought I would ask here in case
someone has run into a similar problem and could provide me with some
additional ideas/pointers...

Appreciate any thoughts and ideas... and Thanks in advance, Marc
User avatar
Darkstar
Posts: 2
Last visit: Fri Feb 17, 2012 4:29 pm

Windows7 script execution puzzle

Post by Darkstar »

Hello - I am new to this forum, found it by Google, and hopefully I am not asking a question that has already been answered, and hopefully this is a good forum to ask. (no joy yet in finding any solutions to this problem I am having....) I have a puzzling problem with a .cmd script, running on a Windows 7 system, which I have written to shutdown a linux computer attached to a common UPS. Within this script I am executing a call to a utility, called plink, to send a command
to the linux system to shut it down -

(plink.exe -v -ssh -P 622 -l root -pw myPassword 192.168.2.100 shutdown
-h now) >> c:TempplinkLog.txt 2>&1
and as you can see I am also redirecting stdout and stderr to a log
file. (and don't be confused about the port number being 622, this is a
security step we use to "hide" the ssh ports on our systems, and the
linux system port forwards it to it's standard ssh port 22)
If I execute this .cmd file directly, either from a command shell
window, or by double clicking on the file's icon, it works! But here is
the problem. I have a Windows service, supplied by the UPS manufacture, that monitors the UPS and if the UPS
gets low on battery power, it has been configured to call this script, which is suppose to
shutdown my linux system. And when it does, it fails. The redirected output to the log file does
not reveal a lot of helpful information -

Looking up host "192.168.2.100"
Connecting to 192.168.2.100 port 622
Failed to connect to 192.168.2.100: Unknown network error
Unable to open connection:
Unknown network error

I have configured the Windows firewall to allow any program an outgoing
connection on port 622. This may be a script security/permissions
problem of some kind but I have been fooling around with those sort of
settings and still no joy. I also know that when this script is called
from the window's service, it is not inheriting any of the system
environment variables. Therefore, part of this script sets the PATH environment
variable, and that much is working since plink is found and is called. I don't
know what, if any, other Windows environment variables may be necessary
for plink to connect successfully to my linux system and I am not sure if there is a way to "restore" all the system environment settings so that they are available within the script?. I
don't know if this is a plink or ssh problem per say, a firewall issue, some kind of permissions issue, or missing environment variables, but I have spent a lot of time exploring all these possibilities and am running
out of ideas. So thought I would ask here in case
someone has run into a similar problem and could provide me with some
additional ideas/pointers...

Appreciate any thoughts and ideas... and Thanks in advance, Marc
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Windows7 script execution puzzle

Post by jvierra »

Sorry but your problem is not a scripting problem.

There is not script her. You have a single command in a file that is a commandline utility that is supplied by a third party vendor.

If you were running a UPS that was configured correctly for multuple systems support you would not need to do this. Look into an APC netork based UPS. It has software modules gor both WIndows and Linux and will do all of the shutdown work without needing to use a script.

If there is a power failure what is the likelyhood that there is no power for the network. The sysem will not work if the netowrk is powered off.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Windows7 script execution puzzle

Post by jvierra »

YOu are running a command under a service. The commands vendor will tellyou it thisis possible.

If the service runs as local machine it may not have access to the network.

None of this has anything to do with scripting.

UPSs need to be netweok based when they support multiple machies ot they will not work as expected. That is why we have network based UPSs.

Modifying your one line batch file will not alter anything. You need to contact the UPS vendor because the service is from the UPS vendor. They will lokely tell you what I have just posted here.

Each machine needs the hartbeat and service for the UPS. Any other scenaripo will not be reliable and, as you have learned, will not likely work.

jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Windows7 script execution puzzle

Post by jvierra »

Every script and batch file always imports all environment variables. They come as part of the shell.




If you did not create any variables in your batch file then the changes you made are probably just something that skirted around some mistaks you have made.

Without your complete batch file this is a futile discussion.
jvierra2012-02-19 07:36:14
This topic is 12 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked