calling script in target machine


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers calling script in target machine
# 1  
Old 05-10-2006
calling script in target machine

I know that schedulers handle callign scripts on different machines. If I want to call a script that's on the target machine and know whether the script ran fine or not, can it be done in shell script?

what kind of commands would that have?

Thank you
# 2  
Old 05-10-2006
Bryan,

How does one run a script remotely on another server?

You can run a scheduler like Tivoli Workload Scheduler, sysADMIRAL, or control-m.

You can always run a cron job as you know.

However, these are not really great for on demand. However, SSH is.

This is really a multi step process. You need to setup SSH correctly and create a key pair and passphrase. Then you need to load your keys into the SSH agent so that you don't get prompted for a passphrase. The SSH agent will handle passing your passphrase to the other systems.

Example:

#ssh-add
Adding identity: /home/tester/.ssh2/id_dsa_1024_defender.pub
Need passphrase for /home/tester/.ssh2/id_dsa_1024_defender.pub
(1024-bit dsa, tester@defender, Sun Apr 30 2000 21:39:13).
Enter passphrase:

#ssh server date
Wed May 10 14:06:57 EDT 2006
#

#Now that you have SSH setup. You can take any script and scp the script to the remote server.



Sample script below
###############################################
#!/bin/sh

LOG="/tmp/MYTEST.log
##################
function if_error
##################
{
if [[ $? -ne 0 ]]; then # check return code passed to function
print "$1 TIME:$TIME" | tee -a $LOG # if rc > 0 then print error msg and quit
exit $?
fi
}

chown root:root /etc/passwd
if_error "Failed chowning /etc/passwd to root:root"

chmod 700 /etc/passwd
if_error "Failed chmoding /etc/passwd to 700"

rm -rf /etc/somedir
if_error "Failed deleting /etc/somedir"
################################################

#Okay..So SSH is working and you got a little test script with the proper error checking in it. Also, I used the tee command to redirect the output of the script to the screen and to a log file in tmp.

scp $USER@$HOST:$PATH/$SCRIPT $USER@$HOST:/tmp/$SCRIPT
ssh -l $USER $HOST chmod 700 /tmp/$SCRIPT
ssh -l $USER $HOST /tmp/$SCRIPT
ssh -l $USER HOST rm /tmp/$SCRIPT

1. Copied script to server
2. Changed permissions
3. Executed script that will write to log file and screen cause I wrote it like that.
4. rm the script


Hope this is helpful.

-X
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reconcilations script between Source and Target

Hi, I am new to DB2 and in need of urgent help. Here we have about 100 queries (SQL) that have been manually executed to retrieve totals from different tables and post it to Excel spreadsheet. Is there any way I can create a shell script as a wrapper and execute these queries and create a... (5 Replies)
Discussion started by: bhaskar v
5 Replies

2. HP-UX

After adding new iscsi target port, still the session state of that target port is showing offline

Hi, I wanted to configure new iscsi port on HPUX system, i added the target port address and configured it, once done, went to array side and searched for that host iqn number , but was nt able to find the same, came to host, then when i ran "iscsiutil -pVS" command it gave me below result ... (0 Replies)
Discussion started by: Vinay Kumar D
0 Replies

3. UNIX for Dummies Questions & Answers

Shell Script for displaying the line till the target word

" Script for display sentences with special character" Hi, Could any one share a command how to display a line until my target word. For ex: My file has the content as: select * from db_wrk where col1 < col2 insert into table_name values('1','2','tst','wrk','dev','prod') My target... (10 Replies)
Discussion started by: Kalaiselvi66
10 Replies

4. Shell Programming and Scripting

Script to run Klocwork from Machine 1 to machine 2

I use Ubuntu 10.04 in 2 virtual machines. In one machine I have installed Hudson and another machine is to run klocwork. Scenario is when I trigger a build in Hudson, the script has to run successful and call the Klocwork in VM2. In the build script I have given the following command to call... (1 Reply)
Discussion started by: bsreeram
1 Replies

5. Shell Programming and Scripting

how to remove the target of the symbol link in a shell script

I have a target directory, there are some files and directories in "target_dir". I have a symbol link: my_link -> <target_dir> The target directory name is NOT known to the script (because it is varying), while the link name is always fixed. In a shell script, how to remove both the... (1 Reply)
Discussion started by: princelinux
1 Replies

6. UNIX for Dummies Questions & Answers

ftp to copy file within target machine

I have ftp'd to a machine and have to copy a file from one directory to other. I thought once I am logged in using ftp, cp command would do it. But when I run the cp command, I get the following: ftp> cp * ../../../../maint/ usage: cp Is using cp the only/right option? Thanks in advance! (2 Replies)
Discussion started by: sunny8107
2 Replies

7. Shell Programming and Scripting

How to transfer files from unix machine to local machine using shell script?

Hi All.. Am new to Unix!! Am creating a shell script in which a scenario is like i have transfer the output file from unix machine (Server) to local directory (Windows xp). And also i have to transfer the input file from the local directory to Unix machine (Server) Any help from you... (1 Reply)
Discussion started by: vidhyaS
1 Replies

8. Shell Programming and Scripting

shell script to copy files frm a linux machine to a windows machine using SCP

I need a shell script to copy files frm a linux machine to a windows machine using SCP. The files keeps changing day-to-day. I have to copy the latest file to the windows machine frm the linux machine. for example :In Linux, On July 20, the file name will be 20.txt and it should be copied to... (3 Replies)
Discussion started by: nithin6034
3 Replies

9. Shell Programming and Scripting

How to execute a script hosted on a machine from a different machine

Hi everyone I intend to trigger a script from one machine say mc1 that actually excutes on different machine say mc2 and redirect the logs to that machine mc2. I tried to use nohup <nfs location of machine >/script.sh > <nfs location of machine >/script.log 2>&1 & nfs location of... (2 Replies)
Discussion started by: harneetmakol
2 Replies

10. UNIX for Advanced & Expert Users

Unix Machine for calling Native Method of C

hi all i have a unix machine (FBD). I have Also installed java of Version (j2sdk1.4.1_07) on unix machine. Now i want to Call C Native function in Java Which is declared as Native. i am doing this by following steps: 1) Making Echo.java File Which is having The following lines of code.... (5 Replies)
Discussion started by: sbeyonduf007
5 Replies
Login or Register to Ask a Question