Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a simple script (Given below) on a machine that collect files from several folders into a single one and then archive it. The script works as expected on the remote machine. When I run it via ssh (ssh user@machine -f 'path.to.script') I get this output

tar: toSend: Cannot stat: No such file or directory tar: Error exit delayed from previous errors Killed by signal 1.

What am I doing wrong?

#!/bin/bash

archfile=~/fastspace/toSend.tgz
dir=~/fastspace/toSend
if [ -f $archfile ] ; then
    rm $archfile
fi

if [ -d $dir ]; then
    rm -r $dir
fi

mkdir $dir

for i in {1..20}; do
    cp ~/fastspace/prog/mn0.$i/resSum.dat $dir/res$i
    cp ~/fastspace/prog/mn0.$i/parOut.dat $dir/pars$i
done

tar cvfz $archfile toSend

rm -r $dir
share|improve this question
    
Try tar cvfz $archfile $dir instead of tar cvfz $archfile toSend. – ott-- Feb 25 '13 at 14:50
    
@ott In that case I get the complete folder tree of toSend instead of the folder itself. Apart from that, this is good. – Yotam Feb 25 '13 at 15:00
    
Ah, then you want to chdir to the folder above. Then change it to tar cvfz $archfile -C ~/fastspace toSend. – ott-- Feb 25 '13 at 15:03
    
Your command isn't accepted by bash. I'm also not sure I understood your suggestion. You suggest I'll log into the remote machine and run it from there? or add chdir line in which I'll go to the folder in which I wish yo place the folders? – Yotam Feb 25 '13 at 15:49
    
You should change the tar command in your script. The -C ~/fastspace means chdir to ~/faszspace before starting to archive the toSend dir`. – ott-- Feb 25 '13 at 16:05

You must log in to answer this question.

Browse other questions tagged .