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
TQSLCERT(1)						      General Commands Manual						       TQSLCERT(1)

NAME
TrustedQSL - digitally sign amateur radio contact logs SYNOPSIS
tqslcert [certificate-file]... tqsl [OPTIONS] [log-file]... DESCRIPTION
TrustedQSL is a file format and set of procedures that is used to send digitally signed QSL information (logs of contacts between amateur radio operators). One notable service that makes use of TrustedQSL is ARRL's Logbook of the World. The tqslcert program is used to generate requests for digital certificates and to store the resulting received digital certificates. The tqsl program is used to digitally sign contact log files using a digital certificate. This manual page briefly documents the tqslcert and tqsl programs. Complete documentation is also available: tqslcert: file:///usr/share/TrustedQSL/help/tqslcert/main.htm tqsl: file:///usr/share/TrustedQSL/help/tqslapp/main.htm OPTIONS
tqslcert accepts TQSL certificate files which may optionally be specified on the command line. tqsl accepts these command line options: -d Suppress date-range dialog. If present, the QSO date-range dialog will not be shown for files that follow this option on the command line. -l location_name Selects an existing station location. This location will be used for the commands that follow. If the station location doesn't exist, tqsl will just exit. -o output_file Writes the resulting signed log file to output_file instead of a default name based on the input log-file name. -s Add or edit station location. If there is a preceding -l option the specified location will be edited. If there is no preceding -l option, a new station location is being added. -x (or) -q Exit tqsl. If this argument is used it should be the last one on the command line. If this argument is not present, tqsl will begin normal operation after successfully processing all command-line arguments. log-files Any command-line parameter that is not an option or an option's argument will be treated as the name of a log file (ADIF or Cabrillo) to be signed. The resulting signed file (.tq8) will be placed in the same directory as the log file, overwriting any existing .tq8 file of the same name. (Note: If this option is not preceded by a -l option that selects the station location to be used for signing, the Select Station Location for Signing dialog will be presented.) File names that contain spaces or other shell- special characters should be quoted in a manner suitable for the operating system and shell that's being used. N.B.: If the private key needed to sign a log is protected by a password, the user will be prompted to supply that password for each file being signed. AUTHOR
trustedqsl was written by "American Radio Relay League, Inc.". This manual page was prepared by Kamal Mostafa <kamal@whence.com>, for the Debian project (and may be used by others). March 31, 2011 TQSLCERT(1)
All times are GMT -4. The time now is 01:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy