Quantcast

awk工具的问题呀。是有点离题了

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

awk工具的问题呀。是有点离题了

jessinio liang
脚本代码:
cat /home/jessinio/TracStat.sh
#!/bin/sh
ps aux | awk '{
    cmd = "";
    do{
    split($0,fields);
    if(fields[12] == "/usr/local/bin/tracd"){
    for(i=11;i<=NF;i++){
            cmd = cmd" "fields[i];
        }
        cmd = cmd "\n";
    }
    }while(getline == 1)
    print cmd;
    exit;
}' | mail -s "trac stat(awk)" -F [hidden email]

crontab -e信息:
*/1     *       *       *       *       /home/jessinio/TracStat.sh



问题:

为什么手动执行程序没有问题!!!

但是crontab执行程序时,邮件是空的!确定一点:awk接收的信息为空!!!

why ???

帮助一下

3Q!




--
身体是革命的本钱!!
blog:http://blog.oldpai.cn
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: awk工具的问题呀。是有点离题了

Jiahua Huang
cron 里边就没有环境变量,没有 PATH ,
你需要使用全路径如 /bin/ps  /bin/bin/awk
或者在脚本开头设 PATH 等

这也是为什么上次我说 #!/bin/python 比 #!/bin/env python 好的原因,
不是所有情况都有环境变量的,

btw: 请不要滥用感叹号

On Jan 9, 2008 11:23 AM, jessinio liang <[hidden email]> wrote:

> 脚本代码:
> cat /home/jessinio/TracStat.sh
> #!/bin/sh
> ps aux | awk '{
>     cmd = "";
>     do{
>     split($0,fields);
>     if(fields[12] == "/usr/local/bin/tracd"){
>     for(i=11;i<=NF;i++){
>             cmd = cmd" "fields[i];
>         }
>         cmd = cmd "\n";
>     }
>     }while(getline == 1)
>     print cmd;
>     exit;
> }' | mail -s "trac stat(awk)" -F [hidden email]
>
> crontab -e信息:
> */1     *       *       *       *       /home/jessinio/TracStat.sh
>
>
>
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: awk工具的问题呀。是有点离题了

jessinio liang
不是这个问题!加了也是一样呢
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: awk工具的问题呀。是有点离题了

Jiahua Huang
别滥用感叹号,你怎么加的?
你怎么确定不是?

On Jan 9, 2008 11:48 AM, jessinio liang <[hidden email]> wrote:
> 不是这个问题!加了也是一样呢
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: awk工具的问题呀。是有点离题了

jessinio liang
  1 #!/bin/sh
  2 /bin/ps aux | /usr/bin/awk '{
  3     cmd = "";
  4     do{
  5     split($0,fields);
  6     if(fields[12] == "/usr/local/bin/tracd"){
  7     for(i=11;i<=NF;i++){
  8             cmd = cmd" "fields[i];
  9         }
 10         cmd = cmd "\n";
 11     }
 12     }while(getline == 1)
 13     print cmd > "/dev/stdout";
 14     exit;
 15 }' | mail -s "trac stat(awk)" -F [hidden email]


--
身体是革命的本钱!!
blog:http://blog.oldpai.cn
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: awk工具的问题呀。是有点离题了

shhgs
ENVIRONMENT
     Mail utilizes the HOME, USER, SHELL, DEAD, PAGER, LISTER, EDITOR,
VISUAL and MBOX environment variables.

在shell下面查查这些环境变量的值,如果不是空的,就加到cron的环境变量里面。

On Jan 8, 2008 10:56 PM, jessinio liang <[hidden email]> wrote:

>   1 #!/bin/sh
>   2 /bin/ps aux | /usr/bin/awk '{
>   3     cmd = "";
>   4     do{
>   5     split($0,fields);
>   6     if(fields[12] == "/usr/local/bin/tracd"){
>   7     for(i=11;i<=NF;i++){
>   8             cmd = cmd" "fields[i];
>   9         }
>  10         cmd = cmd "\n";
>  11     }
>  12     }while(getline == 1)
>  13     print cmd > "/dev/stdout";
>  14     exit;
>  15 }' | mail -s "trac stat(awk)" -F [hidden email]
>
>
> --
> 身体是革命的本钱!!
> blog:http://blog.oldpai.cn
> _______________________________________________
>
> python-chinese
> Post: send [hidden email]
> Subscribe: send subscribe to [hidden email]
> Unsubscribe: send unsubscribe to  [hidden email]
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: awk工具的问题呀。是有点离题了

Jiahua Huang
In reply to this post by jessinio liang
你不还漏了 mail 的全路径么,

你要是想看 mail 前面的又没执行,
就换成   > /tmp/log
像你前边推测的也错在这

On Jan 9, 2008 11:56 AM, jessinio liang <[hidden email]> wrote:

>   1 #!/bin/sh
>   2 /bin/ps aux | /usr/bin/awk '{
>   3     cmd = "";
>   4     do{
>   5     split($0,fields);
>   6     if(fields[12] == "/usr/local/bin/tracd"){
>   7     for(i=11;i<=NF;i++){
>   8             cmd = cmd" "fields[i];
>   9         }
>  10         cmd = cmd "\n";
>  11     }
>  12     }while(getline == 1)
>  13     print cmd > "/dev/stdout";
>  14     exit;
>  15 }' | mail -s "trac stat(awk)" -F [hidden email]
>
>
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: awk工具的问题呀。是有点离题了

jessinio liang
不是路径的问题吧。我的gmail都能收到sendmail命令的信息。

路径问题就不是这样的了
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: awk工具的问题呀。是有点离题了

HG-11
In reply to this post by jessinio liang
慢点来调试,一步一步的排除,这个里面一个用了三个管道,
把他们拆开一步一步来执行,并且把每一步的结果记录下来就
可以找到问题了


On Jan 9, 2008 11:23 AM, jessinio liang <[hidden email]> wrote:

> 脚本代码:
> cat /home/jessinio/TracStat.sh
> #!/bin/sh
> ps aux | awk '{
>     cmd = "";
>     do{
>     split($0,fields);
>     if(fields[12] == "/usr/local/bin/tracd"){
>     for(i=11;i<=NF;i++){
>             cmd = cmd" "fields[i];
>         }
>         cmd = cmd "\n";
>     }
>     }while(getline == 1)
>     print cmd;
>     exit;
> }' | mail -s "trac stat(awk)" -F [hidden email]
>
> crontab -e信息:
> */1     *       *       *       *       /home/jessinio/TracStat.sh
>
>
>
> 问题:
>
> 为什么手动执行程序没有问题!!!
>
> 但是crontab执行程序时,邮件是空的!确定一点:awk接收的信息为空!!!
>
> why ???
>
> 帮助一下
>
> 3Q!
>
>
>
>
> --
> 身体是革命的本钱!!
> blog:http://blog.oldpai.cn
> _______________________________________________
> python-chinese
> Post: send [hidden email]
> Subscribe: send subscribe to [hidden email]
> Unsubscribe: send unsubscribe to  [hidden email]
> Detail Info: http://python.cn/mailman/listinfo/python-chinese



--
关注LAMP平台、安全、及web开发的个人blog: http://hackgou.itbbq.com
PGP KeyID: hackgou#Gmail.com
PGP KeyServ: subkeys.pgp.net
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: awk工具的问题呀。是有点离题了

jiyong wu
In reply to this post by jessinio liang
把你的 /home/jessinio/TracStat.sh
改成这样试试:

ps aux |awk -F '/usr/local/bin/tracd' 'NF>1{print substr($0,length($1))}' | mail -s "trac stat(awk)" -F [hidden email]


On  0, jessinio liang <[hidden email]> wrote:

> 脚本代码:
> cat /home/jessinio/TracStat.sh
> #!/bin/sh
> ps aux | awk '{
>     cmd = "";
>     do{
>     split($0,fields);
>     if(fields[12] == "/usr/local/bin/tracd"){
>     for(i=11;i<=NF;i++){
>    cmd = cmd" "fields[i];
> }
> cmd = cmd "\n";
>     }
>     }while(getline == 1)
>     print cmd;
>     exit;
> }' | mail -s "trac stat(awk)" -F [hidden email]
>
> crontab -e信息:
> */1     *       *       *       *       /home/jessinio/TracStat.sh
>
>
>
> 问题:
>
> 为什么手动执行程序没有问题!!!
>
> 但是crontab执行程序时,邮件是空的!确定一点:awk接收的信息为空!!!
>
> why ???
>
> 帮助一下
>
> 3Q!
>
>
>
>
> --
> 身体是革命的本钱!!
> blog:http://blog.oldpai.cn
> _______________________________________________
> python-chinese
> Post: send [hidden email]
> Subscribe: send subscribe to [hidden email]
> Unsubscribe: send unsubscribe to  [hidden email]
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: awk工具的问题呀。是有点离题了

jessinio liang
问题所在:ps命令的问题。

把代码中的ps命令换在ls命令就OK了

为什么daemon形式调用ps命令会得不到ps的信息的呢??



--
身体是革命的本钱!!
blog:http://blog.oldpai.cn
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: awk工具的问题呀。是有点离题了

shhgs
ps rely on Environments heavily.

man ps
----------------------------------
ENVIRONMENT VARIABLES
The following environment variables could affect ps:

COLUMNS
   Override default display width.

LINES
   Override default display height.

PS_PERSONALITY
   Set to one of posix, old, linux, bsd, sun, digital... (see section
PERSONALITY below).

CMD_ENV
   Set to one of posix, old, linux, bsd, sun, digital... (see section
PERSONALITY below).

I_WANT_A_BROKEN_PS
   Force obsolete command line interpretation.

LC_TIME
   Date format.

PS_COLORS
   Not currently supported.

PS_FORMAT
   Default output format override.

PS_SYSMAP
   Default namelist (System.map) location.

PS_SYSTEM_MAP
   Default namelist (System.map) location.

POSIXLY_CORRECT
   Don't find excuses to ignore bad "features".

POSIX2
   When set to "on", acts as POSIXLY_CORRECT.

UNIX95
   Don't find excuses to ignore bad "features".

_XPG
   Cancel CMD_ENV=irix non-standard behavior.

In general, it is a bad idea to set these variables. The one exception
is CMD_ENV or PS_PERSONALITY, which could be set to
Linux for normal systems. Without that setting, ps follows the useless
and bad parts of the Unix98 standard.
----------------------------------





On Jan 9, 2008 4:45 AM, jessinio liang <[hidden email]> wrote:

> 问题所在:ps命令的问题。
>
> 把代码中的ps命令换在ls命令就OK了
>
> 为什么daemon形式调用ps命令会得不到ps的信息的呢??
>
>
>
>
> --
> 身体是革命的本钱!!
> blog:http://blog.oldpai.cn
> _______________________________________________
> python-chinese
> Post: send [hidden email]
> Subscribe: send subscribe to [hidden email]
> Unsubscribe: send unsubscribe to  [hidden email]
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: awk工具的问题呀。是有点离题了

Jiahua Huang
In reply to this post by jessinio liang
你什么系统?
Linux 下 gnu ps 在 env -i 下没有问题的,

确认下你的 ps 到底有没有执行,
插入个
ps aux >> /tmp/ps.log
看看吧

On Jan 9, 2008 5:45 PM, jessinio liang <[hidden email]> wrote:
> 问题所在:ps命令的问题。
>
> 把代码中的ps命令换在ls命令就OK了
>
> 为什么daemon形式调用ps命令会得不到ps的信息的呢??
>
>
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: awk工具的问题呀。是有点离题了

jessinio liang
BSD系统
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: awk工具的问题呀。是有点离题了

Wei Jiang-5
In reply to this post by jessinio liang
check the mail from system and restart crond.

2008/1/9 jessinio liang <[hidden email]>:

> 脚本代码:
> cat /home/jessinio/TracStat.sh
> #!/bin/sh
> ps aux | awk '{
>     cmd = "";
>     do{
>     split($0,fields);
>     if(fields[12] == "/usr/local/bin/tracd"){
>     for(i=11;i<=NF;i++){
>             cmd = cmd" "fields[i];
>         }
>         cmd = cmd "\n";
>     }
>     }while(getline == 1)
>     print cmd;
>     exit;
> }' | mail -s "trac stat(awk)" -F [hidden email]
>
> crontab -e信息:
> */1     *       *       *       *       /home/jessinio/TracStat.sh
>
>
>
> 问题:
>
> 为什么手动执行程序没有问题!!!
>
> 但是crontab执行程序时,邮件是空的!确定一点:awk接收的信息为空!!!
>
> why ???
>
> 帮助一下
>
> 3Q!
>
>
>
>
> --
> 身体是革命的本钱!!
> blog:http://blog.oldpai.cn
> _______________________________________________
> python-chinese
> Post: send [hidden email]
> Subscribe: send subscribe to [hidden email]
> Unsubscribe: send unsubscribe to  [hidden email]
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: awk工具的问题呀。是有点离题了

jessinio liang
受 shhgs 的指点,使用ps的w参数,完美解决

头尾13天时间



--
身体是革命的本钱!!
blog:http://blog.oldpai.cn
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Loading...