Operating System - HP-UX
1753784 Members
7129 Online
108799 Solutions
New Discussion юеВ

script giving error throuh crontab

 
Viney Kumar
Regular Advisor

script giving error throuh crontab

Hi All

I have facing a problem in a scripting pls me out. When i m running the script manually it woking fine but through cron tab it is giving error in below portion.

echo "Total swap utilisation is echo "Total swap utilisation is `swap -s | awk '
{
swapused = $9
swapavail = $11
swapusedlen = length(swapused) - 1
swapavailen = length(swapavail) - 1
usedk = substr(swapused,1,swapusedlen)
availk = substr(swapavail,1,swapavailen)
total = availk + usedk
percentage = (usedk / total)*100
printf("%3.0f %\n", percentage)



}'`" >> checklist_$d1

instead of print the value of percentage, it is same percentage in output.
but manually its work
9 REPLIES 9
Mark McDonald_2
Trusted Contributor

Re: script giving error throuh crontab

crontab only has a limited environment,

you must use the full path to the commands in the script.

OR

do PATH=.... at the top of the script and include all necessary paths.
likid0
Honored Contributor

Re: script giving error throuh crontab

Thats the thing, you must be missing a path to the binarys you are using, you can use a PATH=/etc/etc , or load you profile at the begining . .profile
Windows?, no thanks
Viney Kumar
Regular Advisor

Re: script giving error throuh crontab

Hi All

i have tried same but still same probelm

pls look into the changes:--
PATH=$PATH:/usr/symcli/bin:/usr/local/bin:/usr/sbin:/usr/bin
export PATH
echo "Total swap utilisation is `/usr/sbin/swap -s | /usr/bin/awk '
{
swapused = $9
swapavail = $11
swapusedlen = length(swapused) - 1
swapavailen = length(swapavail) - 1
usedk = substr(swapused,1,swapusedlen)
availk = substr(swapavail,1,swapavailen)
total = availk + usedk
percentage = (usedk / total)*100
printf("%3.0f %\n", percentage)
#print $percentage
}'`" >> checklist_$d1


and output is:--
Total swap utilisation is %n, percentage)
#print
}'



James R. Ferguson
Acclaimed Contributor

Re: script giving error throuh crontab

Hi:

Several things are amiss here.

1. There is no 'swap' command for HP-UX. What operating system is this? Did you mean to use 'swapinfo -tam' ?

2. There is an extra double quote following the closing curly brace of the 'awk' script.

3. You can't run the posted snippet in 'cron' unldess you _define_ the 'd1' variable you use in 'checklist_$d1'. Cron tasks do _not_ inherit anything in your login 'profile' since it is not sourced (read) when the crontask is initiated.

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: script giving error through crontab

>printf("%3.0f %\n", percentage)

awk(1) doesn't show that you can use () around printf, just:
printf "%3.0f %%\n", percentage

(And you need to double up the literal "%".)

James R. Ferguson
Acclaimed Contributor

Re: script giving error throuh crontab

Hi (again):

> Dennis: awk(1) doesn't show that you can use () around printf, just: printf "%3.0f %%\n", percentage

Yet this works just fine:

# awk 'END{printf("%3.0f %\n",95.9)}' /dev/null

Regards!

...JRF...
OldSchool
Honored Contributor

Re: script giving error throuh crontab

"3. You can't run the posted snippet in 'cron' unldess you _define_ the 'd1' "

well..it might run and produce "checklist_".
James R. Ferguson
Acclaimed Contributor

Re: script giving error throuh crontab

Hi (again) :

> OldSchool: well..it might run and produce "checklist_".

Yes, that's correct, of course, and I should have said that explicitly rather than inferring "can't" to be equivalent to "should not". I was trying to make the point that the user's environment is not necessarily going to be the same as a login environment unless steps are taken. :-)

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: script giving error throuh crontab

>Dennis: awk(1) doesn't show that you can use () around printf, just: printf "%3.0f %%\n", percentage

>JRF: Yet this works just fine:
# awk 'END {printf("%3.0f %\n",95.9)}' /dev/null

Ah, the Posix standard does allow the optional (). But that missing %% is clearly an error. If you use:
awk 'END{printf("%3.0f % depth\n",95.9)}' /dev/null
You'll get an error, since "% d" is a valid format:
awk: There are not enough parameters in printf statement %3.0f % depth