Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Shell script file check throws [: too many arguments Post 303030324 by Dip on Friday 8th of February 2019 04:45:24 AM
Old 02-08-2019
Shell script file check throws [: too many arguments

While I am trying to check the filename/s in IF statement of a shell script (RedHat Linux 6) I am getting below error:

File check:

Code:
filename_time2=`date --date='yesterday' +%Y-%m-%d`
cd /location/of/the/files/to/copy

if [ -f server.log-$filename_time2* ]
then
                cp server.log-$filename_time2* ../archive/new
                echo Successfully copied
else
                echo No server log files present with timestamp $filename_time2
fi

Code:
This throws the error -        [: too many argument

Throws error when there are multiple files in the location. But when there is 1 file match in the location it is working fine.

I have already tried with below options :

Code:
if [ -f "server.log-$filename_time2*" ]
if [[ -f "server.log-$filename_time2*" ]]
if [[ -f server.log-$filename_time2* ]]

All the above cases it is not throwing error but it returns FALSE and executing the else block although the file is present in the location with timestamp

Could you please help me how I can use the if condition here to check whether the files are present in the location.

Thanks.
 

10 More Discussions You Might Find Interesting

1. Solaris

Passing arguments to a shell script from file while scheduling in cron

Hi, I have a shell script Scp_1.sh for which I have to pass 2 arguments to run. I have another script Scp_2.sh which in turns calls script Scp_1.sh inside. How do I make Scp_1.sh script to read arguments automatically from a file, while running Scp_2.sh? -- Weblogic Support (4 Replies)
Discussion started by: weblogicsupport
4 Replies

2. Shell Programming and Scripting

How to pass arguments to SQL file passed in shell script?

Hi, I am using SYBASE database. in my script i am connecting to DB via using isql. isql -U${S_USER} -S${S_SERV} -D${S_DB} -P${S_PWD} -b0 -w3000 -h0 -s"|" -i${MYDIR}/ABC.sql -oXYZ.txt << FINSQL i am taking a ABC.sql file to use the queries written in it and storing the output in... (3 Replies)
Discussion started by: dazdseg
3 Replies

3. Shell Programming and Scripting

send arguments to a .exe file from a shell script

Folks , can anyone post a sample showing a way to parse a variable containing a string to a .exe file . Thanks Venu (2 Replies)
Discussion started by: venu
2 Replies

4. Shell Programming and Scripting

Reading arguments for a shell script from file

I have a shell script that takes 2 arguments. I will have to execute this script multiple times with different values for the arguments. for example, ./shscript env1 value1 ./shscript env1 value2 ./shscript env2 value3 ./shscript env3 value4 ./shscript env1 value5 ./shscript env3... (24 Replies)
Discussion started by: goddevil
24 Replies

5. Shell Programming and Scripting

php file unable to run shell script with arguments

echo $result=exec("./permit.sh".$_FILES); pls suggest some other method to run shell script in php .:wall::mad: (0 Replies)
Discussion started by: upvan111
0 Replies

6. UNIX for Dummies Questions & Answers

How to check arguments in shell???

for example I have make target file is optional. So can I check whether there is or no? I tried if test $# -eq 1 then path=$1 else path=$2 fi But it doesnt work properlu ;( Please use code tags next time for your code and data. (12 Replies)
Discussion started by: Manueldo
12 Replies

7. Shell Programming and Scripting

Calling shell script within awk script throws error

I am getting the following error while passing parameter to a shell script called within awk script. Any idea what's causing this issue and how to ix it ? Thanks sh: -c: line 0: syntax error near unexpected token `newline' sh: -c: line 0: `./billdatecalc.sh ... (10 Replies)
Discussion started by: Sudhakar333
10 Replies

8. UNIX for Dummies Questions & Answers

Need shell script to check file

Hi Experts, I am not good in writing script. Just stared.I am looking for shell script to check following parameters. 1) Number of files on remote Linux SUSE server.- Any directory and sub directory. 2) I should define number of files in script. Files should be variable. 3) Age of... (2 Replies)
Discussion started by: ApmPerfMonitor
2 Replies

9. UNIX for Beginners Questions & Answers

Passing Arguments to shell script from file is not working as expected.

Hi All, I have below simple shell script in cloudera quick start vm cenos 6 which copy file from source to destination. # file_copy.sh source_dir = ${source_dir} target = ${target_dir} cp source_dir target and my parameter file is like below #parameter_file.txt source_dir =... (4 Replies)
Discussion started by: Narasimhasss
4 Replies

10. UNIX for Beginners Questions & Answers

Shell Script to check a file

I'm required to write a simple shell script that when it runs it writes the output which is a simple barcode to a tmp flat file which I can do the bit I'm struggling with... The next time it runs I need to check the tmp output file to see if that barcode is in the output file and if it is send... (5 Replies)
Discussion started by: worky
5 Replies
ns_info(3aolserver)					    AOLserver Built-In Commands 				       ns_info(3aolserver)

__________________________________________________________________________________________________________________________________________________

NAME
ns_info, ns_server, ns_stats - commands SYNOPSIS
ns_info address ns_info argv0 ns_info boottime ns_info builddate ns_info config ns_info home ns_info hostname ns_info interp ns_info label ns_info log ns_info name ns_info pageroot ns_info platform ns_info server ns_info tcllib ns_info uptime ns_info version ns_server option ?arg arg ...? ns_stats option ?arg arg ...? _________________________________________________________________ DESCRIPTION
ns_info boottime Returns the server boot time in seconds. ns_info config Returns the configuration file name. ns_info home Returns the directory where the AOLserver was installed. ns_info hostname Returns the name of the host on which server is running (e.g., www.myhost.com). ns_info interp Returns the number of the Tcl interpreter currently being used. ns_info label Returns the source code label for the server. If no label was used, "unlabeled" is returned. ns_info log Returns the location of the server log file (e.g., /home/myserver/log/server.log). ns_info name Returns the name of the AOLserver. It's usually "AOLserver." ns_info pageroot returns the directory containing the HTML pages for this virtual server. ns_info platform Returns the name of the platform that the server is running on (e.g., Solaris). ns_info server returns the name of this virtual server. ns_info tcllib returns the directory where the AOLserver Tcl source code resides for this virtual server. ns_info uptime returns the time in seconds that the server has been up. ns_info version returns the version of the AOLserver. SEE ALSO
nsd(1), info(n) KEYWORDS
AOLserver 4.0 ns_info(3aolserver)
All times are GMT -4. The time now is 07:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy