2014-10-30 45 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