Unix shell script - novice question

By jej1216 ยท 4 replies
Feb 3, 2005
  1. Don't know if this is the right forum for this question, but here goes........

    I am just beginning to have to write shell scripts to run SQR processes in UNIX.

    I have a script that is having problems copying a file. My code snippet is:

    #copy output file out_file1
    if [[ -s $out_file1 ]]
    cp $out_file1 /cde/datasnd/CLIENT/$pg_name2.csv
    chmod 666 /cde/datasnd/CLIENT/$pg_name2.csv
    file_date=`date +'%Y%m%d.%H.%M.%S'`
    cp $out_file1 $arc_file
    # Payroll Automation project - copy outbound files to Payroll directories
    $SH_LOC/pr_filecopy.sh O D $arc_file NORUNID
    gzip $arc_file
    chmod 666 $arc_file.gz
    # comment out - mv $out_file1 $DATA_LOC/$pg_name2.csv
    MSG="Process Notice - Output file $out_file1 does not exist"
    SUBJ="Process Notice - $FILE_DB - Output file not found"
    echo $MSG
    # send_message $RECIPIENTS "$MSG" "$SUBJ"

    The error messages I get are:
    + [[ -s /opt/PROD/CLIENT/DATA/group.recog_bw.csv ]]
    + cp /opt/PROD/CLIENT/DATA/group.recog_bw.csv /cde/datasnd/CLIENT/group.recog_bw.csv
    cp: cannot create /cde/datasnd/CLIENT/group.recog_bw.csv: No such file or directory
    + chmod 666 /cde/datasnd/CLIENT/group.recog_bw.csv
    chmod: WARNING: can't access /cde/datasnd/CLIENT/group.recog_bw.csv

    I have checked the folder /cde/datasnd/CLIENT/ and it exists.
    I have looked at the /opt/PROD/CLIENT/DATA/group.recog_bw.csv and it is there and has 777 rights.
    I can manually upload the file into the /cde/datasnd/CLIENT/ with no problems.

    There has to be a script error, but I don't see it.

    Any Unix shell gurus out there?


  2. Nodsu

    Nodsu TS Rookie Posts: 5,837   +6

    Do you have read or execute permissions to all of the directories in the path in question?
    You need r or x permissions for cde, datasnd and CLIENT to be able to create that file.

    How do you upload the file manually? Your script may be running under different credentials.
  3. jej1216

    jej1216 TS Rookie Topic Starter

    Unix shell script - novice question - Reply

    I'll check my permissions on cde, datasnd and CLIENT folders. Is there a way I can set those myself?

    I've written a few scripts that do a similar function, and the code looks the same to me.

    I manuall moved the file by right clicking on the file created in /opt/PROD/CLIENT/DATA/ and downloading it locally, then right clicking on the local copy and uploading it to /cde/datasnd/CLIENT/ using SHH FTP application.
  4. Mictlantecuhtli

    Mictlantecuhtli TS Evangelist Posts: 4,345   +11

    Why are you using double brackets?
  5. Phantasm66

    Phantasm66 TS Rookie Posts: 5,734   +8

    chmod a=rwx {all permissions to all users...}

    chmod u=x {add execute permission for user}

    chmod a=r { read permission for all....}

    chown yourname filename
    {change ownership of filename to yourname}
Topic Status:
Not open for further replies.

Similar Topics

Add your comment to this article

You need to be a member to leave a comment. Join thousands of tech enthusiasts and participate.
TechSpot Account You may also...