Find the answer to your Linux question:
Results 1 to 3 of 3
Hi Guru, I am created this script which works before but for some reason is puking at me now when I tried to run it. Please I will appreciate if ...
  1. #1
    Just Joined!
    Join Date
    Oct 2009
    Location
    Chicago
    Posts
    2

    Save me from this script error

    Hi Guru,

    I am created this script which works before but for some reason is puking at me now when I tried to run it. Please I will appreciate if all the pro out there can take a look at it and help me figure out what is not working.

    I will post the script and the error message: The lines 32 and 33 are the cat lines.

    The search line by line the content of the file 1049listing.txt in 1049result.txt. The search will look for an image name and the word successful or failed and then format the result with awk.

    the files names are also going to be appended with the dates when the script ran.

    ************* THE SCRIPT ***************

    #!/bin/bash

    #### Constants

    NOW=$(date +"%e-%b-%y")
    DAILYSUCCESS="/root/Desktop/script/QAdesk/success-$NOW.txt"
    DAILYFAILED="/root/Desktop/script/QAdesk/failed-$NOW.txt"


    ##### 1st Function

    function check_file
    {

    if [ -e "1049listing.txt" ]; then
    new_list
    else
    echo "Please create a file '1049listing.txt' with a list of all images to duplicate"
    fi
    exit 1
    }



    ##### 2nd Function

    function new_list
    {

    BID=`cat /root/Desktop/script/QAdesk/1049listing.txt`
    for i in $BID; do
    cat /root/Desktop/script/QAdesk/1049result.txt | grep $i | grep successful >> $DAILYSUCCESS
    cat /root/Desktop/script/QAdesk/1049result.txt | grep $i | grep failed >> $DAILYFAILED
    done
    awk {'print $7'} $DAILYSUCCESS > diff.txt
    diff /root/Desktop/script/QAdesk/listingbackup/1049listing_091409.txt diff.txt > /root/Desktop/script/QAdesk/rerun/rerun.txt
    awk {'print $2'} /root/Desktop/script/QAdesk/rerun/rerun.txt > /root/Desktop/script/QAdesk/rerun/newjob.txt
    grep -v "^$" /root/Desktop/script/QAdesk/rerun/newjob.txt > /root/Desktop/script/QAdesk/rerun/rerun.txt
    mv $DAILYSUCCESS /root/Desktop/script/QAdesk/resultbackup
    mv $DAILYFAILED /root/Desktop/script/QAdesk/resultbackup
    cp /root/Desktop/script/QAdesk/rerun/rerun.txt /root/Desktop/script/QAdesk/1049listing.txt

    }

    ### Main script


    if [ "$PWD" = "/root/Desktop/script/QAdesk" ]; then

    check_file

    else

    echo -n "To run script change directory to:/root/Desktop/script/QAdesk"

    fi
    exit 0




    ************* ERROR MESSAGE ********************

    ./test001
    ./test001: line 32: $DAILYSUCCESS: ambiguous redirect
    ./test001: line 33: $DAILYFAILED: ambiguous redirect
    ./test001: line 32: $DAILYSUCCESS: ambiguous redirect
    ./test001: line 33: $DAILYFAILED: ambiguous redirect
    ./test001: line 32: $DAILYSUCCESS: ambiguous redirect
    ./test001: line 33: $DAILYFAILED: ambiguous redirect
    ./test001: line 32: $DAILYSUCCESS: ambiguous redirect
    ./test001: line 33: $DAILYFAILED: ambiguous redirect
    ./test001: line 32: $DAILYSUCCESS: ambiguous redirect
    ./test001: line 33: $DAILYFAILED: ambiguous redirect
    awk: cmd. line:2: fatal: cannot open file `/root/Desktop/script/QAdesk/success-' for reading (No such file or directory)
    mv: cannot stat `/root/Desktop/script/QAdesk/success-': No such file or directory
    mv: cannot stat `3-Oct-09.txt': No such file or directory
    mv: cannot stat `/root/Desktop/script/QAdesk/failed-': No such file or directory
    mv: cannot stat `3-Oct-09.txt': No such file or directory
    [root@redhat48box1 QAdesk]# file diff.txt
    diff.txt: empty
    Last edited by Sojero; 10-04-2009 at 03:01 AM. Reason: Added more facts

  2. #2
    Just Joined!
    Join Date
    Aug 2009
    Location
    Mumbai, India
    Posts
    75
    Hi,

    Please change the NOW variable to
    Code:
    NOW=$(date +"%d-%b-%y")
    The current variable settings for NOW would perhaps work when the day of the month is in double digits. But when the day of month is in single digits, a space is prefixed to the date thereby causing two files to be created. You could verify that by echo'ing the three variable NOW, DAILYSUCCESS & DAILYFAILED

    Ambiguous redirect occur when you try to redirect to two files which is currently the case because of the space in the date value

    --Syd

  3. #3
    Just Joined!
    Join Date
    Oct 2009
    Location
    Chicago
    Posts
    2

    Thumbs up

    syd05

    Thanks it works like a charm now. Appreciate the advice. I salute you as the Guru!!!

    Thanks once again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...