nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

pl. examin this script

This is a discussion on pl. examin this script within the Shell scripting forums, part of the Development/Scripting category; i am having a problem in executing this file, if condition when is am putting wild card "*" then it ...

Register free or login to your existing account and remove all advertisements.


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-20-2008, 12:03 PM
kasimani's Avatar
Senior Member
User
 
Join Date: Jul 2006
Location: India, Delhi
OS: CentOS, RedHat, Fedora, Ubuntu
Posts: 151
Thanks: 3
Thanked 1 Time in 1 Post
Rep Power: 4
kasimani is on a distinguished road
Send a message via Yahoo to kasimani
Question pl. examin this script

i am having a problem in executing this file, if condition when is am putting wild card "*"
then it has problem to run script.
error:
statsdataimport.sh: line 6: [: too many arguments
Files Not there yet

pl have a look on to this problem...
---------------------------------------------------------------------------------------
#!/bin/bash

rm -rf /opt/scripts/lk/*
cd /home/cricarc/

if [ -f "`date -d "1 day ago" "+%d"`_`date +%b |tr '[A-Z]' '[a-z]'`_`date +%Y`"* ]; then
echo good
cp -rf `date -d "1 day ago" "+%d"`_`date +%b | tr '[A-Z]' '[a-z]'`_`date +%Y`* /opt/scripts/lk
else
echo "Files Not there yet"
exit 0;
fi

cd /opt/scripts/lk

gunzip *.gz

sh /opt/scripts/ko.sh
cd /opt/scripts/lk

if [ `mysqladmin -uroot -phexademon ping|grep alive|wc -l` = 1 ]; then

/usr/local/mysql/bin/mysql -uroot -phexademon cricarc < `date -d "1 day ago" "+%d"`_`date +%b | tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_close_of_play
echo "Done 1"
/usr/local/mysql/bin/mysql -uroot -phexademon cricarc < `date -d "1 day ago" "+%d"`_`date +%b | tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_ground
echo "Done 2"
/usr/local/mysql/bin/mysql -uroot -phexademon cricarc < `date -d "1 day ago" "+%d"`_`date +%b | tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_innings
echo "Done 3"
/usr/local/mysql/bin/mysql -uroot -phexademon cricarc < `date -d "1 day ago" "+%d"`_`date +%b | tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_match_award
echo "Done 4"
/usr/local/mysql/bin/mysql -uroot -phexademon cricarc < `date -d "1 day ago" "+%d"`_`date +%b | tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_match_official
echo "Done 5"
/usr/local/mysql/bin/mysql -uroot -phexademon cricarc < `date -d "1 day ago" "+%d"`_`date +%b | tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_player
echo "Done 6"
/usr/local/mysql/bin/mysql -uroot -phexademon cricarc < `date -d "1 day ago" "+%d"`_`date +%b | tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_player_team
echo "Done 7"
/usr/local/mysql/bin/mysql -uroot -phexademon cricarc < `date -d "1 day ago" "+%d"`_`date +%b | tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_scorecard
echo "Done 8"
/usr/local/mysql/bin/mysql -uroot -phexademon cricarc < `date -d "1 day ago" "+%d"`_`date +%b | tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_innings_bowling
echo "Done 9"
/usr/local/mysql/bin/mysql -uroot -phexademon cricarc < `date -d "1 day ago" "+%d"`_`date +%b | tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_team
echo "Done 10"
/usr/local/mysql/bin/mysql -uroot -phexademon cricarc < `date -d "1 day ago" "+%d"`_`date +%b | tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_fall_of_wickets
echo "Done 11"
/usr/local/mysql/bin/mysql -uroot -phexademon cricarc < `date -d "1 day ago" "+%d"`_`date +%b | tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_innings_batting
echo "Done 12"
sleep 1
rm -f /opt/scripts/lk/*
else
service mysql restart

fi

---------------------------------------------------------------------------------------
here is ko.sh

#!/bin/sh
cd /opt/scripts/lk/

listfile(){
mv `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`*_web18_close_of_play `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_close_of_play
mv `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`*_web18_fall_of_wickets `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_fall_of_wickets
mv `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`*_web18_ground `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_ground
mv `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`*_web18_innings `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_innings
mv `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`*_web18_match_award `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_match_award
mv `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`*_web18_match_official `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_match_official
mv `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`*_web18_player `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_player
mv `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`*_web18_player_team `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_player_team
mv `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`*_web18_scorecard `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_scorecard
mv `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`*_web18_innings_bowling `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_innings_bowling
mv `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`*_web18_innings_batting `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_innings_batting
mv `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`*_web18_team `date -d "1 day ago" "+%d"`_`date | awk '{ print $2}'|tr '[A-Z]' '[a-z]'`_`date +%Y`_web18_team
}
listfile | awk '{print $9}' > lp.txt
Reply With Quote
  #2 (permalink)  
Old 12-31-2008, 02:37 PM
Junior Member
User
 
Join Date: Feb 2008
OS: .
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
unSpawn is on a distinguished road
Default

If with "[ -f * ]"-style tests you encounter a "too many arguments" warning you might not be quoting properly (see IFS) so the glob provides more than one item and the test doesn't cater for that. The easiest way to debug that (apart from bashdebug?) is to run the script as 'sh -vx scriptname' because then you will see where it goes awry. IMHO the easiest way would be to expand the script to accept parameters (see "getopts") to differentiate between a single and multiple files and act on that or loop over items while testing. Also it would be more efficient and make for better readability to define variables for the date thingy and use that. Like 'THISDATE=$(date -d "1 day ago" "+%d_%b_%Y"|tr [A-Z [a-z]); if [ -f "${THISDATE}*" ]; then doSomething'?..
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT +5.5. The time now is 01:46 PM.


Powered by vBulletin® Version 3.8.4 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2009 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38