Unexpected EOF while loooking for matching '"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unexpected EOF while loooking for matching '"
# 1  
Old 09-28-2012
Unexpected EOF while loooking for matching '"

Hi everyone, I'm really new in shell scripting and having trouble resolving this error.
Can someone please tell me why I'm getting these errors?

Error Message:
./test.sh: line 50: unexpected EOF while looking for matching `''
./test.sh: line 53: syntax error: unexpected end of file


Code:
#!/bin/sh

counter=0
logloc=/home/songja/ServerLogs
backup=/home/songja/test

## Reads the location of the file systems that needs to be investigated from location.txt
## and save it into an array
while read -r line; do
   Unix_Array[${counter}]=$line;
   let counter=counter+1;
done < location.txt


## Reads Email recipients and save it into an array
num=0
while read -r line; do
    Email_list[${num}]=$line;
    let num=num+1;
done < email.txt


## Checking one file system per loop
for ((i=0;i > counter; i++))
    do
    deletestatus=false;
    ## usage returns how much the file system is full. Ex. 50% => 50
    usage=$(df -P ${Unix_Array[$i]} | grep ${Unix_Array[$i]} | awk '{ print $5}' | sed 's/%//g')
    #if usage is greater than 80%, send email
    if [$usage -gt 80];
        then
        for ((j=0;j > num; j++))
        do
            echo ${Unix_Array[$i]} " is " $usage "% full, the logs that are 7 days older has been removed" |  mail - s "Log notification" ${Email_list[$j]} 
        done
        deletestatus=true;
    elif [$usage -gt 50];
        then
        ## if free space is greater 50 and less than 80, it will not send email
        deletestatus=true;
    else
        ## Safety net
        deletestatus=false;
    fi
    
    if [$deletestatus=true];
        then
        ##Moving Files that are older than 7 days
        $(find . $logloc . -name 'SystemOut_* -mtime +2 -exec mv {} /home/songja/test \;)
        ## Deleting files that are older than 7 days
        $(find . $logloc . - name 'SystemOut_*' -mtime +2 -delete)
    fi
done


location.txt
/var
/home

email.txt
myemail@hotmail.com
hisemail@hotmail.com
# 2  
Old 09-28-2012
does below work? have u tried running it on command prompt?

Code:
 
$(find . $logloc . -name 'SystemOut_* -mtime +2 -exec mv {} /home/songja/test \;)

This User Gave Thanks to vidyadhar85 For This Post:
# 3  
Old 09-28-2012
ops I realized that....i fixed it to
Code:
find /home/mine/ServerLogs -type f -name 'SystemOut_*' -mtime +2 -exec mv {} /home/work/test \;

which works on prompt. However when I run it as a file, it doesn't work Smilie

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.

Last edited by Corona688; 09-28-2012 at 12:26 PM..
# 4  
Old 09-28-2012
Please show us the contents of this file as well as the manner you're attempting to run it.

Why do you have $( ) around so many things? There's no point doing so on a single line by itself, and it will cause strange sounding errors.
# 5  
Old 09-28-2012
Quoting from the code in the first message on this thread:
Code:
    if [$deletestatus=true];
        then
        ##Moving Files that are older than 7 days
        $(find . $logloc . -name 'SystemOut_* -mtime +2 -exec mv {} /home/songja/test \;)
        ## Deleting files that are older than 7 days
        $(find . $logloc . - name 'SystemOut_*' -mtime +2 -delete)
    fi

I assume you're aware that the comments talk about 7 days, but the find commands are working on 2 days.

As Corona688 has already noted, the "$("...")" should be removed surrounding both find statements.

Note that the format of all of your test statements:
Code:
[$usage -gt 80];
[$usage -gt 50];
    and
[$deletestatus=true];

are missing required whitespace. They should be:
Code:
[ $usage -gt 80 ];
[ $usage -gt 50 ];
    and
[ $deletestatus = true ];

respectively. Even if your shell accepts [expr] without a space after [ and a space before ], the expression $deletestatus=true will always evaluate to TRUE because the expression is a non-empty string (the = won't be recognized as a comparison operator unless there is whitespace before and after it).

Also note that you have . $logloc . as the list of directories to be searched in both find statements. Are you intentionally processing the current directory twice?

And you have - name instead of -name in the second find. I'm surprised that find didn't complain that -, name, and SystemOut_* are not directories; but of course it might not have noticed since it may have taken quite a while to remove all files older than 2 day from . and $logloc before trying to open these three names as directories.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. SCO

"Unexpected EOF within #IF, #ifdef or #ifndef" error when rebuilding / relinking SCO OpenServer 5

Hi, I am a new Unix Guru with very little experience but have the task of P2Ving an old HP Proliant ML370 G5 server to VMware ESX 4.1 or ESXi 5.5. System seems to boots fine but when trying to remove HP software, configure TCP/IP or a driver, I am receiving: -------- ... (7 Replies)
Discussion started by: dj_Italian
7 Replies

2. Shell Programming and Scripting

In awk: unexpected EOF while looking for matching `"'

I am trying to get grep with awk command into variable. But facing error. Could someone pls help. $ cat test_file DEPLOYMENT="abc" # com cluster="bcn" $ grep DEPLOYMENT test_file | awk -F "\"" '{ print $2 }' abc $ a=`echo "grep DEPLOYMENT test_file | awk -F \"\\\"\" '{ print $2 }'"` ;... (6 Replies)
Discussion started by: Manasa Pradeep
6 Replies

3. Shell Programming and Scripting

Unexpected EOF while looking for matching `'' when ran from a cron job

Since cPanel does not support deleting emails older then X amount of days I am using the following on a Cron Job. find -P /home/user/mail/domain/ -mindepth 2 -mtime '+366' -type f -printf '"%p"\n' | grep -v '/Important' | grep -v '/.Important' | xargs -I {} rm -r "{}" Executing it via SSH... (4 Replies)
Discussion started by: tiagom
4 Replies

4. Shell Programming and Scripting

Help to resolve unexpected EOF while looking for matching `"' error

Hi, can someone kindly look into my copy script and figure out why am i getting a "unexpected EOF while looking for matching `"' error message #!/bin/ksh -x cd /home/goldenga/test/flag37 if ; then rm copied.ok cd /home/goldenga/test Upper=`ls -t|grep 'qw*'|cut -d "w" -f 2|head... (4 Replies)
Discussion started by: NDalal007
4 Replies

5. Shell Programming and Scripting

Unexpected EOF while looking for matching `"'

I have a piece of Linux script. It tells me some syntax error. I couldn't find it. Please help me to identify them. Thanks. The code looks like this: export ORACLE_SID=MYDB export SPW=`cat /opt/oracle/scripts/.sys_pw_$ORACLE_SID` export check_arch=`sqlplus -s << EOF / as sysdba... (7 Replies)
Discussion started by: duke0001
7 Replies

6. UNIX for Dummies Questions & Answers

unexpected EOF

hello everyone...im having this problem with unexpected EOF with line 85 which is..i cant see whats wrong with it..can any1 plz help me out. read -p "$p1 please enter the number of tries you wish to have:" lifeline function main() { guessnum=0 read -p "Please enter if its sinle player game... (1 Reply)
Discussion started by: Freakhan
1 Replies

7. Shell Programming and Scripting

line 85: unexpected EOF while looking for matching `"'

hello everyone...im having this problem with unexpected EOF with line 85 which is..i cant see whats wrong with it..can any1 plz help me out. read -p "$p1 please enter the number of tries you wish to have:" lifeline function main() { guessnum=0 read -p "Please... (6 Replies)
Discussion started by: Freakhan
6 Replies

8. Shell Programming and Scripting

Unexpected EOF while looking for matching `"'

Hi everyone, I am trying to search for a string in a file that is partly made up of a variable. Here's the code: echo "parentCategory = $parentCategory" echo "parentCategoryFormatted = $parentCategoryFormatted" numUrlsFoundInParentCategory=`grep -c "<Topic r:id=\"Top\/World\/Français\/"... (2 Replies)
Discussion started by: BlueberryPickle
2 Replies

9. Shell Programming and Scripting

"unexpected end of file" when I´m use EOF inside block if

I have a trouble in my script when i use EOF inside block if. If i use EOF whitout block if I don´t have problem. Guys any ideas? Sorry for my terrible English. #!/bin/sh set -xv HOST='ftp.fiction.com.br' USER='fictionuser' PASS='fictionpass' FILE='ftpteste.txt' busca=`find... (4 Replies)
Discussion started by: ricardo.ludwig
4 Replies

10. UNIX for Advanced & Expert Users

unexpected EOF

I ran the following scripts and everytime i get the errot as follows Line 54: unexpected EOF while looking for matching ',' line 57 syntex error unexpected end of file#!/bin/ksh set -x BKUP_DIR=/u03/backups/abu/nightly_backup LOG_FILE=/u03/backups/abu/backup.log ORACLE_HOME=... (9 Replies)
Discussion started by: manna
9 Replies
Login or Register to Ask a Question