Run Multiple Functions over SSH (BASH)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run Multiple Functions over SSH (BASH)
# 1  
Old 08-20-2008
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 the same directory structure when copying the files.

The question is, how can I run multiple commands and custom functions over ssh? I have a function 'recurse' that I want to run remotely however I am at a loss for how to do it. I thought of creating the script on the remote machine and running it through ssh, however the remote is a Mac and I don't know much about shell scripting on a Mac.

Is this even possible to do with a BASH script? Should I be using PERL or something a little more powerful? Thanks, any help is much appreciated.
# 2  
Old 08-20-2008
What's wrong with scp -r? Or set up rsync between the two machines. This is assuming you want the whole structure, not specific individual files.
# 3  
Old 08-21-2008
I've thought about rsync, which would work for the file transfer, but I left out two important steps when describing the script in my first post.

1) the script must update an m3u playlist on the remote machine to point to the file once it has been moved
2) the file should be deleted once the script is run

for step one, I need to be able to create a variable containing the file path that I can write to the m3u, thus I don't think rsync will completely fill my needs here.
# 4  
Old 08-22-2008
I'd approach this in two steps; run rsync, and then when you know the result, ssh back to the remote machine and run a script which deletes the files (unless you already did that with an rsync option) and update the playlist file.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ssh to multiple hosts and then run multiple for loops under remote session

Hello, I am trying to login to multiple servers and i have to run multiple loops to gather some details..Could you please help me out. I am specifically facing issues while running for loops. I have to run multiple for loops in else condition. but the below code is giving errors in for... (2 Replies)
Discussion started by: mohit_vardhani
2 Replies

2. Shell Programming and Scripting

Calling Bash Functions in the BG

I'm trying to call some functions in the background so that I can multitask in this script. Not working so hot. The functions I call don't ever seem to get called. I'm doing it the exact same way in another script and it's working like a champ so I'm very confused. Here's a pretty simple repro: ... (7 Replies)
Discussion started by: stonkers
7 Replies

3. Shell Programming and Scripting

Run multiple commands in ssh

Hi All, I have the below requirement. I want to copy the local file to remote after that i need to run the local script on a remote machine.When i use two ssh commnds i can achieve this. But i want to achieve this using one ssh command. Below command to copy the local file to remote ssh -q... (2 Replies)
Discussion started by: mohanalakshmi
2 Replies

4. Shell Programming and Scripting

How to run multiple functions in Background in UNIX Shell Scripting?

Hi, I am using ksh , i have requirement to run 4 functions in background , 4 functions call are available in a case that case is also in function, i need to execute 1st function it should run in background and return to case and next i will call 2nd function it should run in background and... (8 Replies)
Discussion started by: karthikram
8 Replies

5. Shell Programming and Scripting

Bash Scipting (New); Run multiple greps > multiple files

Hi everyone, I'm new to the forums, as you can probably tell... I'm also pretty new to scripting and writing any type of code. I needed to know exactly how I can grep for multiple strings, in files located in one directory, but I need each string to output to a separate file. So I'd... (19 Replies)
Discussion started by: LDHB2012
19 Replies

6. Ubuntu

How to run kernel functions in a separate core?

Hello Friends, I am using Ubundu. I want to know how to run kernel functions in a separate core? I know about Taskset and it supports only for the application. Do anybody know any command (or) have any idea about how to do it? Please help me Thank you (3 Replies)
Discussion started by: reksss
3 Replies

7. 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

8. 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

9. Shell Programming and Scripting

bash, ssh and expect to multiple ip addresses

Hi, I need script that will allow me to connect to multiple clients using ssh on Ubuntu terminal... I have a txt file with the ip addresses of clients, i need a script that will connect to everyone one by one and send some commands... The idea is to check some settings on every client... (2 Replies)
Discussion started by: marko07
2 Replies

10. Shell Programming and Scripting

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 :) I'm suspecting that it would be... (1 Reply)
Discussion started by: columb
1 Replies
Login or Register to Ask a Question