Operating System - HP-UX
1821467 Members
2842 Online
109633 Solutions
New Discussion юеВ

Re: batch script to execute unix command?? how??

 
SOLVED
Go to solution
amonamon
Regular Advisor

batch script to execute unix command?? how??

I would like to ask how to execute UNIX command thru batch script??

can someone give me a hint how to make batch script that can execute script on unix??

any ideas??
19 REPLIES 19
Arunvijai_4
Honored Contributor

Re: batch script to execute unix command?? how??

Hi,

Try using Cron. Check this out: http://www.aota.net/Script_Installation_Tips/cronhelp.php3

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
amonamon
Regular Advisor

Re: batch script to execute unix command?? how??

I know cron that is OK but I need batch script...withput cron ..
Arunvijai_4
Honored Contributor

Re: batch script to execute unix command?? how??

Hi,

Do you want to write startup script ? or any shell script to automate something ? "Batch script" is a windoze word.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
amonamon
Regular Advisor

Re: batch script to execute unix command?? how??

no not start up script...I was wondering just on double click on my batch script I can execute one UNIX script on my UNIX...I need that becouse of previous programming..

so just to be able to execute script from windows and execute UNIX script on my solaris machine..
Peter Godron
Honored Contributor

Re: batch script to execute unix command?? how??

Hi,
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1034456 covers the difference between .bat and .sh.

For help on how to write shell script:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=940583

or at the simplest level:
create a file,calling it a.sh, which contains:

#!/usr/bin/sh
ls

then chmod 700 a.sh
to execute './a.sh'
which will list your directory
spex
Honored Contributor

Re: batch script to execute unix command?? how??

Hi amonamon,

If you're talking about writing a shell script to execute different programs successively, here's a general template:

#!/usr/bin/sh
/
/
exit 0

So if you wanted to write a script that:
1) lists the contents of /var/tmp, and then
2) reports system uptime,
you could write the following to a file:

#!/usr/bin/sh
/usr/bin/ls /var/tmp
/usr/bin/uptime
exit 0

Let's say you wrote this block to /home/user1/scripts/script01.sh. To be able to execute script01.sh, you must make sure it has execute permission:

# cd ~user1/scripts
# ls -l script01.sh
-rw-r--r-- 1 root root 0 Jul 11 08:21 script01.sh
# chmod u+x script01.sh
# ls -l script01.sh
-rwxr--r-- 1 root root 0 Jul 11 08:21 script01.sh

Then to execute it:
# ./script01.sh

Here's an execellent user's guide to shells under HP-UX:

http://docs.hp.com/en/B2355-90046/

If you're not able to execute some pre-existing scripts, make sure they have execute permission, and that you're logged in as a user having sufficient privileges to run them.

PCS
amonamon
Regular Advisor

Re: batch script to execute unix command?? how??

I think noone understands me..

On my windows machine XP machine...I want to create file file1.bat

On that file I want something like this:

telenet 123.456.798.123
root
root
here command to execute script on UNIX machine ./script

exit

so I need batch script on windows...
Peter Godron
Honored Contributor

Re: batch script to execute unix command?? how??

The batch job will not be able to supply the pasword at the prompt, so you will need a telnet client.
See
http://www.computing.net/dos/wwwboard/forum/14210.html
Torsten.
Acclaimed Contributor

Re: batch script to execute unix command?? how??

This is the first time you menioned the windows OS!

The windows telnet cannot be scripted, you need another "telnet-able" application or any windows versions of unix like applications for this.
Best solution will be an ssh client.

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
spex
Honored Contributor
Solution

Re: batch script to execute unix command?? how??

amonamon,

You've got many options. One is to install OpenSSH for Windows:

http://sshwindows.sourceforge.net/

Then generate a public/private key for the Windows client, and copy the public key to the HP-UX server (this will allow you to log in without a password):

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1005579

Then you can do something like:

C:\> ssh hpux_server command

This line could be added to a Windows batch file, if so desired.

A second option is to create an HP-UX user for the express purpose of running a script. Then add the path to the script to that user's ~/.profile (followed by "exit"), and log in as that user from the Windows client via Telnet or SSH. As soon as you login as that special user, the script will run, after which point the session will close.

PCS
amonamon
Regular Advisor

Re: batch script to execute unix command?? how??

OK thanks for answer so it is imposible to write batch script and supply pass. for remote UNIX machine...

I did not know that it is imposible..but thanks for answer..
Frank de Vries
Respected Contributor

Re: batch script to execute unix command?? how??

I have 2 ideas,

1) You can script a windows batch file
to do an ftp to put a file on unix.

Well this gives rise to a few creative
possibilities.

You could on unix run a bacground job
that checks every 20 seconds for a file and if newer then executes your unix script.

This would work and is quite simple to implement.

2) You could also install nfs client with Samba this way you can run executable or batch on windows and trigger something on Unix platform. This is more heavy to configure.
We use this for our Oracle tools which are ├В┬╡
windows based but need Unix as well.

Good luck:))

Look before you leap
Sandman!
Honored Contributor

Re: batch script to execute unix command?? how??

hi amonamon,

You need to download Expect for Windows, it's a great tool for automating Unix hosts from your Windows client...get it from here:

http://expect.nist.gov/

~cheers
Dave La Mar
Honored Contributor

Re: batch script to execute unix command?? how??

Another option is a remote exec application running on your Windows machine.
Google search for REXEC and REXECD for windows.
There are many remote exec products for windows available and some you will find as freeware.

Disclaimer:
Remote exec is a severe security risk. If the machines in question are accessible only in an internal ip environment, rexec is a viable option. If the machine ip is open to the world this is not a good option.

Regards,

-dl
"I'm not dumb. I just have a command of thoroughly useless information."
Jeffrey L. Cooke
Occasional Advisor

Re: batch script to execute unix command?? how??

After all this discussion on a batch script, I would like to simply suggest using the "at" command.

"at" is a one-shot run-in-the-future batch facility that is usually available to non-root users.
Taurian
Valued Contributor

Re: batch script to execute unix command?? how??

Hello All,

Can anyone please tell me how to configure the "OpenSSH" software so that it does not prompt for a password?

The scenario is that I want to shutdown HP-UX machines from a Windows machine. I want to create a batch file in windows that will run shutdown scripts in all the servers one by one. This I want to do without any human intervention.

I have installed "OpenSSH" on my windows machine and executed 'ssh root@'. Initially it showed an RSA key. I made a text file in windows and put the key in it and then copied it to the '/home/root/.ssh' directory on my server that is running HP-UX. It does not show the key when I run 'ssh root@' on windows, but it prompts for a password, for which human intervention is required.

Please let me know what step I am missing.
OldSchool
Honored Contributor

Re: batch script to execute unix command?? how??

also, look at the "r" commands in Windows. may have to be added, it been a while since I've done this.

remsh, rexec .....

then in bat1.bat

remsh /path/to/script

might get the job done....


You also might have better luck posting in a Windows forum as well

Steven E. Protter
Exalted Contributor

Re: batch script to execute unix command?? how??

Etiquette folks.

This thread was asleep for 6 weeks.

Please leave scripts the author has let languish alone and post your questions yourselves.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Taurian
Valued Contributor

Re: batch script to execute unix command?? how??

System Administrator:
Thanks for the reply. REXEC also prompts for a password and I can't find any option to provide it with a password. Anywayz... shifting my question to a new thread.

Steven E. Protter:
Thanks for the reminder. I thought the same discussion could remain in the same thread. Anywayz, posting my query in a new thread :)