linux - Bash script not producing desired result -


i running cron-ed bash script extract cache hits , bytes served per ip address. script (proxyusage.bash) has 2 parts:

  1. (uniqueip.awk) find unique ips , create bash script add hits , bytes
  2. run hits , bytes per ip

proxyusage.bash

#!/usr/bin/env bash sudo gawk -f /home/maxg/scripts/uniqueip.awk /var/log/squid3/access.log.1 > /home/maxg/scripts/pxyusage.bash source /home/maxg/scripts/pxyusage.bash 

uniqueip.awk

{   arrips[$3]++; }  end {    (n in arrips) {     m++;                               # count arrips elements     #print "array elements: " m;     arraddr[i++] = n;                  # fill arraddr ips     #print " " n;   }    asort(arraddr);                      # sort array values    (i = 1; <= m; i++) {           # write 1 command line per ip address     #printf("#!/usr/bin/env bash\n");     printf("sudo gawk -f /home/maxg/scripts/proxyusage.awk -v v_var=%s /var/log/squid3/access.log.1 >> /home/maxg/scripts/pxyusage.txt\n", arraddr[i])   } } 

pxyusage.bash

sudo gawk -f /home/maxg/scripts/proxyusage.awk -v v_var=192.168.1.13 /var/log/squid3/access.log.1 >> /home/maxg/scripts/pxyusage.txt sudo gawk -f /home/maxg/scripts/proxyusage.awk -v v_var=192.168.1.14 /var/log/squid3/access.log.1 >> /home/maxg/scripts/pxyusage.txt sudo gawk -f /home/maxg/scripts/proxyusage.awk -v v_var=192.168.1.22 /var/log/squid3/access.log.1 >> /home/maxg/scripts/pxyusage.txt 

theproxyusage.bash script runs scheduled , creates pxyusage.bash script. pxyusage.text file not amended latest values when script runs. far run pxyusage.bash every day myself, cannot figure out, why result not written file.

both bash scripts set execute. file permissions below:

-rwxr-xr-x  1 maxg maxg  169 mar 14 08:40 proxysummary.bash -rw-r--r--  1 maxg maxg  910 mar 15 17:15 proxyusage.awk -rwxrwxrwx  1 maxg maxg  399 mar 17 06:10 pxyusage.bash -rw-rw-rw-  1 maxg maxg 2922 mar 17 07:32 pxyusage.txt -rw-r--r--  1 maxg maxg  781 mar 16 07:35 uniqueip.awk 

any hints appreciated. thanks.

the sudo(8) command requires pseudo-tty , not have 1 allocated under cron(8); do have 1 allocated when logged in usual way.

instead of mucking sudo(8), run script correct user.

if cannot that, in root crontab, this:

su - username /path/to/mycommand arg1 arg2...

this work because root can use su(1) without neding password.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

gradle error "Cannot convert the provided notation to a File or URI" -