stderr stdout to a log file

I originally wrote my script using the korn shell and had to port it to bash on a another server. My script is working find for backing up but noticed that now after the move, I am not getting any output to my log files.

Using Korn shell, this worked for me for some odd reason. This was sending stdout and stderr to a file:

find /home/testuser -depth  | cpio -oavc | gzip > /media/backup_drive/test.cpio.gz 2> /media/backup_drive/inc$date.log

Here is the line in the script where I expect to see any error go to my errout.log

find /home/testuser -depth | cpio -oavc | gzip > /media/backup_drive/test.cpio.gz 2> /media/backup_drive/errout.log

in my errout.log its all garbage. I tried everything, stdout and stderr to a log file but the same gargage:

find /home/testuser -depth  | cpio -oavc | gzip > /media/backup_drive/test.cpio.gz 2>&1 >/media/backup_drive/errout.log
find /home/testuser -depth  | cpio -oavc | gzip > /media/backup_drive/test.cpio.gz  /media/backup_drive/errout.log 2>&1

Any ideas ???

Which part of your pipeline is giving you the errors that you want trapped?

The way you have the pipeline written only gzip errors will be sent to the log file. If you want all errors, from any process in the pipe, written to the log try this:

(find /home/testuser -depth | cpio -oavc | gzip >/media/backup_drive/test.cpio.gz) 2>/media/backup_drive/errout.log

The pipeline is run in a sub-shell and the stderror from the subshell (all processes) will be sent to the log file.

If the errors you are trying to trap are just from gzip, then I'm not sure what is going on as your code looks ok from the brief scan I did.

many thanks for the reply,

actually what I was trapping before was the output of find, so that in the log files, it would show what was being backed up such as directories and files. Here is an older log file when it worked using ksh:

/home/test/scripts/backups/test_include
/home/test/scripts/backups/elmo_exclude
/home/test/scripts/backups/include
/home/test/scripts/backups
/home/test/scripts
/home/test

Also if I have variables such as:

home=/home/testuser
search=find
archive=cpio -oavc
zip_it=gzip
backup_dir=/media/backup_drive

$search $home -depth | $archive -oavc | $zip_it >/media/backup_drive/test.cpio.gz 2>/media/backup_drive/errout.log

Is there any special brackets that should enclose the brackets? remember I am using the bacj shell

home=/home/testuser
search=find
archive=cpio -oavc
zip_it=gzip
backup_dir=/media/backup_drive

(($search $home -depth | $archive -oavc | $zip_it >/media/backup_drive/test.cpio.gz)) 2>/media/backup_drive/errout.log

I am a junior coder, please bare with me. thanks

---------- Post updated at 10:44 AM ---------- Previous update was at 10:18 AM ----------

it appears to have worked many thanks