[SOLVED] variable defined in awk, not working. !!!
Solaris / OpenSolarisThis forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
DIR=/home/user/sha
dte=`date | awk '{print $3}'`
mnt=`date | awk '{print $2}'`
cd $DIR
mkdir $dte${mnt}2011_files
cd $dte${mnt}2011_files
mkdir pro stp
ls -ltrh protrace* | awk -v dte="${dte}" '{if ($7 -eq dte) print $9}' > /tmp/tpro
/usr/bin/mv -fi `cat /tmp/tpro` $DIR/$dte${mnt}2011_files/pro/
cd DIR/$dte${mnt}2011_files/pro/
zip -19q $dte${mnt}2011_files_protrace.zip *
Looking at the above I don't think you will get the results you are looking for.
After this step cd $dte${mnt}2011_files you are standing in /home/user/sha/22Sep2011_files. The ls -ltrh protrace* command is done from inside that directory. The result will always be zero files because you just created that directory.
You are probably missing part of the ls command: ls -ltrh /path/to/protrace*
I just missed that cd /path/ while pasting. its going on right path creating right directories zipping everything is going well..just that its taking all files of protrace irrespective of date.
Hmmm i dont know how to use BB code exactly.. but as you told in my previous question gone through some doc and i believe i have to use that before i start my script ie.,
Code:
restofthescript
? isnt it. if this is not the method then i really have to learn first BBcode.
Please just make that awk command to take only today's file that would resolve my prob.
I do have to warn you about using ls this way: The ls output is _not_ consistent when it comes to dates, you might get into trouble when looking for older files. Also: if you have files with spaces in them the above will also not work (instead of $9, you might need to print $9, $10 etc).
Try looking at the find command when time permits: find - examples
But error still exist. i even tried giving single quote to $6 == 'mnt' it also didnt work out.
quote:
ls -ltrh protrace* | awk -v mnt="${mnt}" -v dte="${dte}" '{if ($6 == mnt && $7 == dte ) print $9}'
output(error):
++ ls -ltrh protrace.old protrace.t1 protrace.t2 protrace.t3
++ awk -v mnt=Sep -v dte=22 '{if ($6 == mnt && $7 == dte) print $9}'
awk: syntax error near line 1
awk: bailing out near line 1
BTW1: ls -ltrh -> then trh part isn't needed (especially the r part), ls -l will do.
BTW2: cd DIR/$dte${mnt}2011_files/pro/ should be cd $DIR/$dte${mnt}2011_files/pro/
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
On Solaris 10 and older, avoid to use /usr/bin/awk which is only there not to break compatibility with legacy scripts that might stay around, use /usr/bin/nawk or /usr/xpg4/bin/awk instead.
NOw its working.. The difference was "" (double quotes for $mnt and $dte Earlier code:
ls -l protrace* | awk '{ if ( $6 == '$mnt' && $7 == '$dte' ) print $9 }' > /tmp/tpro
NOw its working.. The difference was "" (double quotes for $mnt and $dte Earlier code:
ls -l protrace* | awk '{ if ( $6 == '$mnt' && $7 == '$dte' ) print $9 }' > /tmp/tpro
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.