添加crontab守护程序

时间:2011-11-30 14:11:47

标签: perl bash sockets crontab

我正在尝试使用简单的perl程序模拟套接字客户端。

套接字客户端:

#!/usr/bin/perl
#path: /home/nuthan/client1
use IO::Socket;
my $sock = new IO::Socket::INET ( PeerAddr => 'xx.xx.xx.xx',  PeerPort => '11050',     Proto => 'tcp',  );
die "Could not create socket: $!\n" unless $sock;
    use POSIX 'strftime';
$time=strftime("%H%M%S",localtime) . "\n";
$date=strftime("%d%m%y",localtime)."\n";
$data="#00000##0#0000#AUT#1#V#07734.7000,E,1259.5355,N,000.00,288#$date#$time##";
print $data;
print $sock "$data";
close($sock);

命令:执行

的bash脚本
#!/bin/bash
#path: /bin/server
set PATH=/usr/bin/perl
export PATH
/home/nuthan/client1
#perl home/nuthan/client1

crontab命令:

每60秒运行一次此套接字客户端。

* * * * * server 2>&1 >> /var/log/client.log

错误:最后,我收到此错误!!!

No command 'bin' found, did you mean:
 Command 'win' from package 'wily' (universe)
 Command 'tin' from package 'tin' (universe)
 Command 'bip' from package 'bip' (universe)
 Command 'bing' from package 'bing' (universe)
 Command 'bins' from package 'bins' (universe)
bin: command not found

我哪里错了!!!!?请帮忙!!!

2 个答案:

答案 0 :(得分:1)

您不应将PATH设置为perl可执行文件,而应设置为包含您要使用的工具的目录,例如

export PATH=/bin:/usr/bin

答案 1 :(得分:0)

@TLP感谢您的帮助。搞定了!!!

<强> bash中:

  #!/bin/sh
  set PATH=/usr/bin/perl
  export PATH=/bin:/bin
  /home/nuthan/clients/client1

cron命令:

 * * * * * /usr/bin/perl /bin/client1 2>&1 >> /home/nuthan/logs/client1.log

记录客户端@ /home/nuthan/logs/client1.log