Shell script simple if then :: fi missing ]


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script simple if then :: fi missing ]
# 1  
Old 10-10-2011
Shell script simple if then :: fi missing ]

If file exists then do stuff else do nothing...
Code:
#! /bin/sh

if [ -r /home/dudemgnt/public_html/fileserver/Checks/Daily/RefundChecksDaily*.txt]
then
     rm /home/dudemgnt/public_html/fileserver/Checks/Daily/RefundChecksDaily.csv
     cat /home/dudemgnt/public_html/fileserver/Checks/Daily/RefundChecksDaily*.txt|sed  's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > /home/dudemgnt/public_html/fileserver/Checks/Daily/RefundChecksDaily.csv
     perl -ne 'chomp;
            m|^(.*)\b(\d+)/(\d+)/(\d+)\b(.*)$|;
            printf ("%s%04d-%02d-%02d%s\n", $1,$4,$2,$3,$5)
           ' /home/dudemgnt/public_html/fileserver/Checks/Daily/RefundChecksDaily.csv > /home/dudemgnt/public_html/fileserver/Checks/Daily/RefundChecksDaily.csv
     mysql -ududemgnt -phithere666 dudemgnt_patCopy -B < /home/dudemgnt/mysql_scripts1234/Import_FTPChecks.sql
fi

if [ -r /home/dudemgnt/public_html/fileserver/BW/Daily/DataBw*.txt]
then
     rm /home/dudemgnt/public_html/fileserver/BW/Daily/DataBw.csv
     cat /home/dudemgnt/public_html/fileserver/BW/Daily/DataBw*.txt|sed  's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > /home/dudemgnt/public_html/fileserver/BW/Daily/DataBw.csv
     perl -ne 'chomp;
            m|^(.*)\b(\d+)/(\d+)/(\d+)\b(.*)$|;
            printf ("%s%04d-%02d-%02d%s\n", $1,$4,$2,$3,$5)
           ' /home/dudemgnt/public_html/fileserver/BW/Daily/DataBw.csv > /home/dudemgnt/public_html/fileserver/BW/Daily/DataBw.csv
     mysql -ududemgnt -phithere666 dudemgnt_patCopy -B < /home/dudemgnt/mysql_scripts1234/CallLogDaily.sql
fi

When run:
Code:
[: 12: missing ]
[: 22: missing ]


Last edited by zaxxon; 10-10-2011 at 07:45 AM.. Reason: indention
# 2  
Old 10-10-2011
What is a syntax error obiously, will be those lines:
Code:
if [ -r /home/dudemgnt/public_html/fileserver/Checks/Daily/RefundChecksDaily*.txt]

which are missing a blank in the back before the closing square bracket:
Code:
... ecksDaily*.txt ]

You can use set -x for example debug at least the shell script part as a start.
Also some code intendtion is very helpful. I did that for you in this piece of code.
This User Gave Thanks to zaxxon For This Post:
# 3  
Old 10-10-2011
Thanks but there is another cryptic error.
Code:
#! /bin/sh
set -x
if [ -r /home/dudemgnt/public_html/fileserver/Checks/Daily/RefundChecksDaily*.txt ]; then
rm /home/dudemgnt/public_html/fileserver/Checks/Daily/RefundChecksDaily.csv
cat /home/dudemgnt/public_html/fileserver/Checks/Daily/RefundChecksDaily*.txt|sed  's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > /home/dudemgnt/public_html/fileserver/Checks/Daily/RefundChecksDaily.csv
perl -ne 'chomp;
            m|^(.*)\b(\d+)/(\d+)/(\d+)\b(.*)$|;
            printf ("%s%04d-%02d-%02d%s\n", $1,$4,$2,$3,$5)
           ' /home/dudemgnt/public_html/fileserver/Checks/Daily/RefundChecksDaily.csv > /home/dudemgnt/public_html/fileserver/Checks/Daily/RefundChecksDaily.csv
mysql -ududemgnt -phi_there665 dudemgnt_patCopy -B < /home/dudemgnt/mysql_scripts1234/Import_FTPChecks.sql 
fi

if [ -r /home/dudemgnt/public_html/fileserver/CallLog/Daily/CallLogDaily*.txt ]; then
rm /home/dudemgnt/public_html/fileserver/CallLog/Daily/CallLogDaily.csv
cat /home/dudemgnt/public_html/fileserver/CallLog/Daily/CallLogDaily*.txt|sed  's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > /home/dudemgnt/public_html/fileserver/CallLog/Daily/CallLogDaily.csv
perl -ne 'chomp;
            m|^(.*)\b(\d+)/(\d+)/(\d+)\b(.*)$|;
            printf ("%s%04d-%02d-%02d%s\n", $1,$4,$2,$3,$5)
           ' /home/dudemgnt/public_html/fileserver/CallLog/Daily/CallLogDaily.csv > /home/dudemgnt/public_html/fileserver/CallLog/Daily/CallLogDaily.csv
mysql -ududemgnt -phi_there665 dudemgnt_patCopy -B < /home/dudemgnt/mysql_scripts1234/CallLogDaily.sql 
fi

if [ -r /home/dudemgnt/public_html/fileserver/BW/Daily/DataBw*.txt ]; then
rm /home/dudemgnt/public_html/fileserver/BW/Daily/DataBw.csv
cat /home/dudemgnt/public_html/fileserver/BW/Daily/DataBw*.txt|sed  's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > /home/dudemgnt/public_html/fileserver/BW/Daily/DataBw.csv
perl -ne 'chomp;
            m|^(.*)\b(\d+)/(\d+)/(\d+)\b(.*)$|;
            printf ("%s%04d-%02d-%02d%s\n", $1,$4,$2,$3,$5)
           ' /home/dudemgnt/public_html/fileserver/BW/Daily/DataBw.csv > /home/dudemgnt/public_html/fileserver/BW/Daily/DataBw.csv
mysql -ududemgnt -phi_there665 dudemgnt_patCopy -B < /home/dudemgnt/mysql_scripts1234/DataBw.sql 
fi

./hospitalfile_imports.sh
+ [ -r /home/dudemgnt/public_html/fileserver/Checks/Daily/RefundChecksDaily.txt /home/dudemgnt/public_html/fileserver/Checks/Daily/RefundChecksDaily012811_151423.txt ]
[: 1: /home/dudemgnt/public_html/fileserver/Checks/Daily/RefundChecksDaily.txt: unexpected operator
+ [ -r /home/dudemgnt/public_html/fileserver/CallLog/Daily/CallLogDaily*.txt ]
+ [ -r /home/dudemgnt/public_html/fileserver/BW/Daily/DataBw*.txt ]

What does the set -x do and did i place it correctly?

---------- Post updated at 07:26 AM ---------- Previous update was at 07:24 AM ----------

Intention is to load sql files from text files if necessary... the sql is nothing more than :

LOAD DATA LOCAL INFILE '/home/dudemgnt/public_html/fileserver/BW/Daily/DataBw.csv' INTO TABLE `IMPORT_DataBW_FTP` FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
# 4  
Old 10-10-2011
Your file description contains a wildcard, so that will be expanded. It does not necessarily follow that it will do "If readable file1 or if readable file2 or if readable file 3......" You have to be sure that your expanded file description leaves you a valid statement.



I hope that this helps.
Robin
Liverpool/Blackburn
This User Gave Thanks to rbatte1 For This Post:
# 5  
Old 10-10-2011
Yeah that does help. I can change the name with the wildcard first and then see if it exists...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compilation error character is missing-UNIX shell script

Dear Friends, Regarding Compilation error character is missing-unix shell script I am new to unix shell script. My requirement is --I need to find out 3 files in my UBM unix directory,if any one(CMUSER) file is available means,then i need to exit from my unix script, Below is my unix... (2 Replies)
Discussion started by: Joseph2017
2 Replies

2. UNIX for Advanced & Expert Users

Checking missing data's sequence (shell script | UNIX command)

Dear All members, i have some trouble here, i want to ask your help. The case is: I have some data, it's like: -ABCD1234 -ABCD1235 -ABCD1237 -BCDE1111 -BCDE1112 -BCDE1114 there is some missing data's sequence (the format is: ABCD = name 1234 = sequence). I want to print the... (2 Replies)
Discussion started by: septian.tri
2 Replies

3. Shell Programming and Scripting

Simple Shell Script! Almost Done!

Hello, I am creating a shell script and I am almost done. I have certain things I want done in the shell but don't know how to finish it properly. Here is what I am aiming to do. I am aiming to have a shell that takes at least 3 parameters. The first two are the two words to replace (the... (3 Replies)
Discussion started by: ShellsNewb
3 Replies

4. Shell Programming and Scripting

Simple Shell Script? Someone help?

Write a shell script which adds up 10 numbers entered by the user and displays the result to the screen. You must use the read command to obtain the numbers from the user. Im a nooby noob (2 Replies)
Discussion started by: LinuxNubBrah
2 Replies

5. Shell Programming and Scripting

Help with simple Shell Script

Hi , I am in need of simple shell script that has one input file containing some words Input file 1 : ****ALEX***JOHN*******VIRGIL***** CHRITINE*****FAISAL*****DON***** ****ALEX***JOHN*******VIRGIL***** CHRITINE*****FAISAL*****DON***** ****ALEX***JOHN*******VIRGIL*****... (6 Replies)
Discussion started by: kmanjuna
6 Replies

6. Shell Programming and Scripting

simple shell - how to get a parameter typed in a shell script

Hi, I am new to unix and using linux 7.2. I would like to create a script that would make it easyer for me to run my java programms. At the moment I have to type java myJavaprogram I am trying to write a script that will allow me to type something like this "myscript myJavaprogram" or maybe... (4 Replies)
Discussion started by: cmitulescu
4 Replies

7. Shell Programming and Scripting

Need help in a simple shell script

Hi All I have requirement to write a shell script which would look for the userid which is logged in , and once the User id is found i would delete certain lines from a parameter file .. here is what iam using a=ps -o user | grep -v user | uniq then using an if condition and... (4 Replies)
Discussion started by: raghav1982
4 Replies

8. UNIX for Advanced & Expert Users

I need of a simple shell script

Hi, I need of a simple shell script to launch a perl script. The complet path of the script is: /export/home/x2693/project/v02/appliancemanagement.pl (2 Replies)
Discussion started by: Minguccio75
2 Replies

9. Shell Programming and Scripting

Please Help On Simple Shell Script

This is an assignment I have to do everyone but I was viewing the threads and I assumed that I could write this assignment simpler than what My instructor is directing.. Here is the Assignment This shell script has the following specifications: - It must be named: "printpasswd." - It must... (1 Reply)
Discussion started by: dmosheye
1 Replies

10. Shell Programming and Scripting

need a simple shell script

Hi, I am new to unix as well as shell programming. Any body can provide me a simple shell script which should copy/transfer/fetch a file(using FTP)from remote server to local system.and it should log the details when it was fetched.If there is any error,the error msg should log in log... (1 Reply)
Discussion started by: Mar1006
1 Replies
Login or Register to Ask a Question