Run function from script over ssh (BASH)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run function from script over ssh (BASH)
# 1  
Old 05-28-2009
Run function from script over ssh (BASH)

Hi,

Is there any cleaver way to run function from the bash scrip over ssh?

For example:

#!/bin/bash
#Function 1
FN1 ()
{
ls -l
}

#Main run
ssh user@host FN1
exit 0

Yeah, I know it will not work, but I'm asking how to make it to work Smilie
I'm suspecting that it would be impossible to do that, but then one never know!

Many thanks in advance!
Cheers
Chris
# 2  
Old 05-28-2009
Quote:
Originally Posted by columb
Hi,

Is there any cleaver way to run function from the bash scrip over ssh?

For example:

When you post code, please wrap it in [code] tags.
Quote:
Code:
#!/bin/bash
#Function 1
FN1 () 
{
ls -l
}

#Main run
ssh user@host FN1 
exit 0

Yeah, I know it will not work, but I'm asking how to make it to work Smilie
I'm suspecting that it would be impossible to do that, but then one never know!

You must define the function in the remote shell:

Code:
ssh user@host "FN1() 
{
ls -l
}
FN1
"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[bash] running a function remotely using ssh

Hi all. I need a bash script to run a function remotely. I think it should be similar to the following but can't figure out the exact syntax. Here is the script: #!/bin/bash function nu () { for var in {0..5}; do printf "$var, "; done; echo } ssh host "$(typeset -f); nu" ... (9 Replies)
Discussion started by: ziguy
9 Replies

2. Shell Programming and Scripting

Run recursive function with variables over SSH

Hi, I don't know if you can help or if this is even possible, but I am trying to run the following function over an ssh and (depending on the itteration I choose) keep getting unexpected token or undefined symbol errors. The function is: killtree() { typeset parent=$1 typeset child... (1 Reply)
Discussion started by: RECrerar
1 Replies

3. Shell Programming and Scripting

ssh run script error

Hello when try to excute the following ssh -l pla 10.287.60.55 vis_fil vis_fil not found. but it works fine when login to the server. can you help me run this command in one online because i will add later to shell script regards (1 Reply)
Discussion started by: mogabr
1 Replies

4. Shell Programming and Scripting

ssh to run bash script

I want to use ssh to start a bash script that I have uploaded to a webhost. How do I do that from linux? (2 Replies)
Discussion started by: locoroco
2 Replies

5. UNIX for Dummies Questions & Answers

Using SSH to run a "BASH" script.

Experts, Hello ! Im running into something that I cant seem to find an answer to. I have a script and it does the following set of actions - 1. Cd to one specific directory 2. Look for all the files that contain a string and once a occurence of the string is found, 3. Pipe that output to... (8 Replies)
Discussion started by: OMLEELA
8 Replies

6. Shell Programming and Scripting

howto run remotely call function from within script

Hi I have the following script : #!/bin/ksh #################### Function macAddressFinder ######################## macAddressFinder() { `ifconfig -a > ipInterfaces` `cat ipInterfaces` } ####################################################################### # # print... (2 Replies)
Discussion started by: presul
2 Replies

7. Shell Programming and Scripting

Running a function on a remote server via SSH in a script

I'm working on a script (mostly for practice) to simplify a task I have to do every now and then. I have a cluster with 6 servers on it, each server has a directory with a set of files called *.pid and *.mpid. Each file contains the pid of a process that may or may not be running on that server.... (3 Replies)
Discussion started by: DeCoTwc
3 Replies

8. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

9. Shell Programming and Scripting

Run Multiple Functions over SSH (BASH)

I am trying to write a script that will ssh into a remote machine and recurse through a specified directory, find mp3 files which may be two or three directories deep (think iTunes: music/artist/album/song.mp3), and scp them back to the machine running the script. The script should also maintain... (3 Replies)
Discussion started by: johnnybg00de
3 Replies

10. Shell Programming and Scripting

Script to do a function on all files in one run

Hello everybody I am trying to write a script in Cshell solaris 8 to read a number of files and do some commands on them (for example extracting some information) and send the results to one single file. I want to do that for all the files in one run. Could any body advise me on it. Thanks and... (5 Replies)
Discussion started by: Reza Nazarian
5 Replies
Login or Register to Ask a Question