- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Can anyone find a bug in this code?? shell script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2006 05:59 PM
тАО09-18-2006 05:59 PM
Can anyone find a bug in this code?? shell script
nawk -F"|" '
{ s=substr($104,2,18)}
{b[s] ++s}
END { for (i in b) print i, b[i] } ' $1 > /path/to/files/TranId_w$2
q=`cat /path/to/files/TranId_w$2 | wc -l`
echo $q > /path/to/files/zaCGSN
nawk -F"|" -v x=$2 -v w=$(cat zaCGSN) '
{u=u+1; l=l+$66}
($66 != 0)&&($110 == 1)&&($111 == 0) { a=a+1; s=s+$66}
END { print x"|"u"|"l"|"w"|"s } ' $1 >> statistic
rm /path/to/files/TranId_w$2
rm zaCGSN
./ftp_PC statistic
and I execute it ./script1 file1 20061212
I think problem is somewhere in second nawk..becouse in cron I can see TranId_w$2 created every day but statistic is not updated..
can anyone help me with debug..
Regards..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2006 06:10 PM
тАО09-18-2006 06:10 PM
Re: Can anyone find a bug in this code?? shell script
ivan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2006 06:44 PM
тАО09-18-2006 06:44 PM
Re: Can anyone find a bug in this code?? shell script
When you run it from the command line the script inherits the variables defined in your shell, most notably the PATH.
Cron has no such environment, you need to tell it everything it should know. So either you could define a PATH variable at the beginning of your job, or you should fully qualify all commands you use. So, if you run nawk from /usr/local/bin make sure you specify "/usr/local/bin/nawk" instead of just using "nawk".
HtH,
Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2006 06:59 PM
тАО09-18-2006 06:59 PM
Re: Can anyone find a bug in this code?? shell script
env
In cron, that same command produces:
HOME=user's-home-directory LOGNAME=user's-login-id PATH=/usr/bin:/usr/sbin:. SHELL=/usr/bin/sh
And that's it. When you write *any* script, it is a good idea to never assume anything, whether it is $PATH or $PWD. Changes I would make:
Always use the interpreter line as line 1:
#!/usr/bin/sh
Always explicitly state your PATH - never use the current one:
export PATH=/usr/bin
Never use any patch that is relative (ie, ./ftp)
The grave accents have been deprecated for 10 years. Use the construct $() as in:
q=$(cat /path/to/files/TranId_w$2 | wc -l)
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2006 10:02 PM
тАО09-18-2006 10:02 PM
Re: Can anyone find a bug in this code?? shell script
in addition to the above suggestions, I want to warn about the construct w=$(...) in:
nawk -F"|" -v x=$2 -v w=$(cat zaCGSN) '...
If the file zaCGSN contains one or more blanks, there will be a syntax error this (n)awk command.
Use
nawk -F"|" -v x=$2 -v w="$(cat zaCGSN)" '...
instead.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2006 10:10 PM
тАО09-18-2006 10:10 PM
Re: Can anyone find a bug in this code?? shell script
echo $q > /path/to/files/zaCGSN
you use the full path to the file "zaCGSN", and in
nawk -F"|" -v x=$2 -v w=$(cat zaCGSN) '
you use a relative path as if you were in the same directory.
With no full path to the file I suppose that the cat command will fail.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2006 11:51 PM
тАО09-18-2006 11:51 PM
Re: Can anyone find a bug in this code?? shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-19-2006 11:21 PM
тАО09-19-2006 11:21 PM
Re: Can anyone find a bug in this code?? shell script
I guess that the second parameter you pass to your script looks like a date.
If you want this to be excecuted by cron with an updated date you, perhaps, wrote in your crontab something like :
/path/script1 file1 $( date +'%Y%m%d' )
This does not work well because the % character is interpreted as a separator by cron.
Regards,
JPH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-20-2006 12:12 AM
тАО09-20-2006 12:12 AM
Re: Can anyone find a bug in this code?? shell script
to complete JPH remark:
if you want to use the percent sign in a crontab commandline, you have to double it:
/path/script1 file1 $(date +'%%Y%%m%%d')
mfG Peter