2014-10-30 43 views
0

我有开机运行在领新启动脚本:运行一圈请求

的/ etc /初始化/ selfconfig

#! /bin/sh 
# /etc/init.d/selfconfig 

USER=root 
HOME=/root 

export USER HOME 

/usr/bin/perl /boot/coder_settings/saconfig.pl 

exit 0 

这个脚本运行的Perl脚本

/boot/coder_settings/saconfig.pl

#! /usr/bin/perl 

lwp-request -m GET http://192.168.1.16:3000/hostname > /boot/coder_settings/hostname.txt 

但我得到这个错误:

Search pattern not terminated at /boot/coder_settings/saconfig.pl line 3.

我在做什么错?

+0

尝试:LWP请求-m GET 'http://192.168.1.16:3000/hostname'> /boot/coder_settings/hostname.txt – michael501 2014-10-30 22:52:37

回答

1

尽管lwp-request是一个perl脚本,它的设置是作为命令行程序运行的。

你可以简单地改变你的bash脚本;

#! /bin/sh 
.... 
/usr/bin/perl /boot/coder_settings/saconfig.pl 

To;

#! /bin/sh 
.... 
lwp-request -m GET http://192.168.1.16:3000/hostname > /boot/coder_settings/hostname.txt 

如果你想运行lwp-request作为perl的shell命令,使用反引号将你的perl脚本更改为;

#! /usr/bin/perl 

`lwp-request -m GET http://192.168.1.16:3000/hostname > /boot/coder_settings/hostname.txt` 
+1

圣钼你说得对!我只需要添加包装perl脚本的反引号。谢谢! – Devin 2014-10-31 02:00:57