简体   繁体   English

iMac上的Shell脚本不再与High Sierra一起使用

[英]Shell Script on iMac no longer working with High Sierra

I recently upgraded my iMac 27” (mid-2011) from Yosemite to High Sierra and I am struggling to get back some functionality that I had working previously! 我最近将我的iMac 27英寸(2011年中)从优胜美地升级到了High Sierra,我正努力找回以前使用的某些功能!

To briefly explain… First of all, I grab local weather data from weather underground using some Python scripts on a Raspberry pi3. 简要说明一下……首先,我在Raspberry pi3上使用一些Python脚本从地下天气中获取本地天气数据。 These scripts also massage the data and then create and store an XML file on the pi. 这些脚本还会处理数据,然后在pi上创建并存储XML文件。 I also, on the pi, run a http server that looks for calls. 我还在pi上运行一个http服务器来查找呼叫。

On an iPad, using iRule, I have a button that is called 'Weather Forecast'. 在使用iRule的iPad上,我有一个名为“天气预报”的按钮。 When this button is pressed it triggers a network resource on my ISY994i (Insteon) controller that, in turn, makes a call to the http server on the pi sending it a parameter. 按下此按钮时,它将触发我的ISY994i(Insteon)控制器上的网络资源,该控制器依次调用pi上的http服务器并为其发送参数。 When the pi receives the call and validates the parameter, it runs another Python script (on the pi) that takes the data in the previously created XML file and puts it into a proper format for the next step. 当pi收到调用并验证参数时,它将运行另一个python脚本(在pi上),该脚本将先前创建的XML文件中的数据获取,并以适当的格式进行下一步。 Finally, that script sends GET requests to the iMac, through Apache2, to read the weather forecast out loud. 最后,该脚本通过Apache2将GET请求发送到iMac,以大声读取天气预报。

This was working very well on Yosemite but now that I have upgraded the saying part is not working! 这在优胜美地上效果很好,但是现在我已经升级了, 说的那部分无法正常工作!

I have 3 shell scripts on the iMac that are called, from the pi, in this process… 我在iMac上有3个shell脚本,在此过程中,它们从pi调用了……

saysomethinghttp9a.sh This is the first script called which reads the current volume level and stores it in a local file (on the iMac); saidomethinghttp9a.sh这是第一个调用的脚本,该脚本读取当前的音量级别并将其存储在本地文件中(在iMac上); then it changes the volume level to an acceptable volume (I use 18); 然后将音量更改为可接受的音量(我使用18);

!/bin/bash
echo -e "Content-type: text/html\n"

PHRASE=`echo "$QUERY_STRING" | sed -n 's/^.*phrase=\([^&]*\).*$/\1/p' | sed "s/+/ /g" | sed "s/%20/ /g"`

cat << junk
<html>
<head>
<title>
saying
</title>
</head>
<body>
junk

currVol=$(osascript -e "get volume settings")

echo "Current Volume Setting = $currVol"

var1=$( echo $currVol | cut -d":" -f1 )
var2=$( echo $currVol | cut -d":" -f2 )
origVol=$( echo $var2 | cut -d"," -f1 )
echo $origVol
parm="set volume output volume $origVol"
echo $parm

destfile="/Users/Sarah/Sound_Volume/Volume1.txt"
echo $parm > $destfile

osascript -e "set volume output volume 18"

cat << junk
</body>
</html>
junk

saysomethinghttp9.sh After the volume level has been set, this script does the 'say' part based upon what is sent from the pi. saidomethinghttp9.sh设置音量级别后,此脚本将根据pi发送的内容执行“说”部分。 The pi calls this script and sends a parameter, which is the words I want said. pi调用此脚本并发送一个参数,这就是我想要说的话。 This call is repeated several times for the intro, date, time, weather forecast and closing; 对于介绍,日期,时间,天气预报和结束,此呼叫重复多次。 and

#!/bin/bash

echo -e "Content-type: text/html\n"

PHRASE=`echo "$QUERY_STRING" | sed -n 's/^.*phrase=\([^&]*\).*$/\1/p' | sed "s/+/ /g" | sed "s/%20/ /g"`

cat << junk
<html>
<head>
<title>
saying
</title>
</head>
<body>
junk

say "Hey There"

cat << junk
</body>
</html>
junk

saysomethinghttp9b.sh Finally this last script is called, which reads the original volume from the file created in the first step and then resets the volume to that level. saidomethinghttp9b.sh最后,将调用最后一个脚本,该脚本从第一步中创建的文件中读取原始卷,然后将其重置为该级别。

#!/bin/bash
echo -e "Content-type: text/html\n"

cat << junk
<html>
<head>
<title>
saying
</title>
</head>
<body>
junk

file="/Users/Sarah/Sound_Volume/Volume1.txt"
echo $file
read -d $'\x04' parm < "$file"
echo $parm

osascript -e "$parm"

cat << junk
</body>
</html>
junk

( note that I go through the steps to adjust the volume because the volume for music, from iTunes, is much too loud for the 'say' commands ) 请注意,由于iTunes上音乐的音量对于'say'命令来说太大了,因此我需要逐步调整音量,因为

In trying to figure out what is wrong I have tried numerous things: 在试图找出问题所在时,我尝试了很多事情:

  • I edited the script saysomethinghttp9.sh to eliminate the 'say' of a parameter passed to it and simply put in the line say “Hey there” ( note that the code above is the edited version ) 我编辑了脚本saysomethinghttp9.sh,以消除传递给它的参数的“说”,然后简单地在行中说“ Hey there”( 请注意,上面的代码是已编辑的版本

  • I then opened up a terminal session on the iMac and issued the commands from there... 然后,我在iMac上打开了一个终端会话,并从那里发出命令...

    • ./saysomethinghttp9a.sh ./saysomethinghttp9a.sh

    • ./saysomethinghttp9.sh ./saysomethinghttp9.sh

    • ./saysomethinghttp9b.sh ./saysomethinghttp9b.sh

All 3 scripts worked when called from the terminal so that wasn't the problem. 从终端调用时,所有3个脚本均有效,所以这不是问题。

To debug the calls to the iMac, I simplified the process by eliminating the iPad, the pi and the ISY994i from the process. 为了调试对iMac的调用,我简化了流程,从流程中删除了iPad,pi和ISY994i。 Instead, I have been trying to make the calls to the iMac from a PC on the same network using a browser. 相反,我一直在尝试使用浏览器从同一网络上的PC拨打iMac的电话。

The result from running the scripts directly from the browser, on the PC, was that script saysomethinghttp9a.sh and saysomethinghttp9b.sh worked but saysomethinghttp9.sh did not! 直接从PC上的浏览器运行脚本的结果是脚本saysomethinghttp9a.shsaysomethinghttp9b.sh起作用了,但是saysomethinghttp9.sh没有起作用

Here are the Access and Error log entries from the iMac after trying the calls from the browser on the PC… 在尝试从PC上的浏览器进行调用之后,这是iMac的访问和错误日​​志条目…

Access Log 访问日志

10.0.1.195 - - [18/Dec/2017:21:33:30 -0500] "GET /cgi-bin/saysomethinghttp9a.sh HTTP/1.1" 200 197

10.0.1.195 - - [18/Dec/2017:21:34:04 -0500] "-" 408 -

10.0.1.195 - - [18/Dec/2017:21:33:44 -0500] "GET /cgi-bin/saysomethinghttp9.sh HTTP/1.1" 200 53

10.0.1.195 - - [18/Dec/2017:21:33:49 -0500] "GET /cgi-bin/saysomethinghttp9.sh HTTP/1.1" 200 53

10.0.1.195 - - [18/Dec/2017:21:35:05 -0500] "GET /cgi-bin/saysomethinghttp9b.sh HTTP/1.1" 200 135

Error Log 错误记录

[Mon Dec 18 21:34:44.356130 2017] [cgi:warn] [pid 29997] [client 10.0.1.195:60109] AH01220: Timeout waiting for output from CGI script /Library/WebServer/CGI-Executables/saysomethinghttp9.sh

[Mon Dec 18 21:34:44.356519 2017] [core:error] [pid 29997] (70007)The timeout specified has expired: [client 10.0.1.195:60109] AH00574: ap_content_length_filter: apr_bucket_read() failed

[Mon Dec 18 21:34:49.949284 2017] [cgi:warn] [pid 29575] [client 10.0.1.195:60107] AH01220: Timeout waiting for output from CGI script /Library/WebServer/CGI-Executables/saysomethinghttp9.sh

[Mon Dec 18 21:34:49.949652 2017] [core:error] [pid 29575] (70007)The timeout specified has expired: [client 10.0.1.195:60107] AH00574: ap_content_length_filter: apr_bucket_read() failed

For full disclosure, my programming experience is relatively limited. 为了全面披露,我的编程经验相对有限。 I often piece things together using examples that I find online. 我经常使用在网上找到的示例将事情拼凑起来。

I do not know how to interpret the errors noted above! 我不知道如何解释上述错误! The only information I could find related to "The timeout specified has expired" was related to situations where a lot of data was being dealt with! 我能找到的与“指定的超时时间已到期”有关的唯一信息与正在处理大量数据的情况有关! In my case, there is very little data being processed! 就我而言,正在处理的数据很少!

I would appreciate some help or direction on how to proceed. 我将对如何进行提供一些帮助或指导。

Edit: 编辑:

After reading the comments from Mark Setchell, I added into my script the '/usr/bin/id' and ran the script first in the terminal and saw that user name was correct. 阅读了Mark Setchell的评论后,我在脚本中添加了“ / usr / bin / id”,并首先在终端中运行了该脚本,并看到用户名正确。 Then I ran the same script from the other PC and saw that the user name was '_www'! 然后,我在另一台PC上运行了相同的脚本,看到用户名是“ _www”! So I then edited the httpd.conf (apache2) file and changed the section include User Sarah and Group staff . 因此,我然后编辑了httpd.conf(apache2)文件,并更改了包括用户SarahGroup staff的部分 However this did not correct the problem! 但是,这不能解决问题!

Next I read up on how to 'use su to become that user and try the script'. 接下来,我将学习如何“使用su成为该用户并尝试使用脚本”。 Through the readings I kept finding suggestions to use sudo instead and finally found a suggestion to edit the sudoers file. 通过阅读,我不断找到使用sudo的建议,最后找到了编辑sudoers文件的建议。 So I did this using the command sudo visudo . 所以我使用命令sudo visudo做到了这一点。 Then I added in the following line 然后我在以下行中添加了

Sarah ALL=(ALL) NOPASSWD: ALL 莎拉ALL =(ALL)NOPASSWD:全部

Then I tried running the script from the PC once again however this time the script ran and is saying again! 然后,我尝试再次从PC运行该脚本,但是这次脚本运行了,并在一遍!

After reading the comments from Mark Setchell, I added into my script the '/usr/bin/id' and ran the script first in the terminal and saw that user name was correct. 阅读了Mark Setchell的评论后,我在脚本中添加了“ / usr / bin / id”,并首先在终端中运行了该脚本,并看到用户名正确。 Then I ran the same script from the other PC and saw that the user name was '_www'! 然后,我在另一台PC上运行了相同的脚本,看到用户名是“ _www”! So I then edited the httpd.conf (apache2) file and changed the section include User Sarah and Group staff. 因此,我然后编辑了httpd.conf(apache2)文件,并更改了包括用户Sarah和Group人员的部分。 However this did not correct the problem! 但是,这不能解决问题!

Next I read up on how to 'use su to become that user and try the script'. 接下来,我将学习如何“使用su成为该用户并尝试使用脚本”。 Through the readings I kept finding suggestions to use sudo instead and finally found a suggestion to edit the sudoers file. 通过阅读,我不断找到使用sudo的建议,最后找到了编辑sudoers文件的建议。 So I did this using the command sudo visudo . 所以我使用命令sudo visudo做到了这一点。 Then I added in the following line 然后我在以下行中添加了

Sarah ALL=(ALL) NOPASSWD: ALL 莎拉ALL =(ALL)NOPASSWD:全部

Then I tried running the script from the PC once again however this time the script ran and is saying again! 然后,我尝试再次从PC运行该脚本,但是这次脚本运行了,并在一遍!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM