LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-17-2015, 02:14 PM   #1
C4rtm4N
LQ Newbie
 
Registered: Feb 2015
Distribution: Raspian
Posts: 5

Rep: Reputation: Disabled
Problem with running Bash Script


Hi

I have just started to use Linux on my Raspberry Pi to host a home automation server & I'm having a problem when trying to run a bash script.

The script in question is to turn off my Viera TV & is as follows
Code:
#!/bin/sh
curl -i \
-H "Accept: text/xml" \
-H "Cache-Control: no-cache" \
-H "Pragma: no-cache" \
-H 'SOAPACTION: "urn:panasonic-com:service:p00NetworkControl:1#X_SendKey"' \
-H "Content-Length: 200" \
-H 'Content-Type: text/xml;charset="utf-8"' \
-X POST --data '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> \
<s:Body> \
<u:X_SendKey xmlns:u="urn:panasonic-com:service:p00NetworkControl:1"> \
<X_KeyEvent>NRC_POWER-ONOFF</X_KeyEvent> \
</u:X_SendKey> \
</s:Body> \
</s:Envelope>' http://192.168.1.87:55000/nrc/control_0/
If I run this from the command line it works fine but when I try to run it from within the Home Automation application it returns error code 32512 which I've seen elsewhere is actually exit status 127 & basically down to not being able to find the program to execute.

Permissions are fine & I've tried using the full path name for both curl and the script itself but I still get the error. Has anyone any idea what I need to change as this looks to be a pure Linux (or rather my misunderstanding of Linux) issue rather than the home automation program

Thanks

Steve
 
Old 02-18-2015, 12:05 PM   #2
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Quote:
'<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> \
<s:Body> \
<u:X_SendKey xmlns:u="urnanasonic-com:service00NetworkControl:1"> \
<X_KeyEvent>NRC_POWER-ONOFF</X_KeyEvent> \
</u:X_SendKey> \
</s:Body> \
</s:Envelope>'
Perhaps if you use single quote then '\' should not be used. So try using this instead:

Code:
'<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:X_SendKey xmlns:u="urn:panasonic-com:service:p00NetworkControl:1"><X_KeyEvent>NRC_POWER-ONOFF</X_KeyEvent></u:X_SendKey></s:Body></s:Envelope>'
 
1 members found this post helpful.
Old 02-18-2015, 02:57 PM   #3
C4rtm4N
LQ Newbie
 
Registered: Feb 2015
Distribution: Raspian
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thanks veerain

Again I can paste this onto the command line & it turns the TV off but I can't run the script.

At least there looks to be progress as from the prompt in Bash I get "/bin/sh^M: bad interpreter: No such file or directory" now or if I run it as sudo I get "No such file or directory"
Not sure of the correct Linux terminology but there's a shortcut to sh in that folder - is my problem something to do with the #!/bin/bash or #!/bin/sh that I'm stating at the start of my script?

Syntax is a killer for those of us not used to Linux

Thanks

Steve
 
Old 02-18-2015, 02:59 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Did you write that script on a Windows system and then copy it onto the RPi by any chance?

The ^M at the end of the line is a dead giveaway that the file does not have proper Unix line endings. You can also tell from the output of the "file" command, it will tell you the line ending style used for the file. Use the dos2unix utility to convert it if necessary.
 
1 members found this post helpful.
Old 02-18-2015, 03:29 PM   #5
C4rtm4N
LQ Newbie
 
Registered: Feb 2015
Distribution: Raspian
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thanks suicidaleggroll - that was my issue all along!

I thought that I'd been really careful by using Notepad++ but clearly I wasn't careful enough & I need to use dos2Unix a lot more in the future

Regards

Steve

Last edited by C4rtm4N; 02-18-2015 at 03:31 PM.
 
Old 02-18-2015, 06:30 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
You can tell notepad++ to use unix line endings

Also, instead of quoting, a cleaner look can be to use a here document:
Code:
curl -i \
-H "Accept: text/xml" \
-H "Cache-Control: no-cache" \
-H "Pragma: no-cache" \
-H 'SOAPACTION: "urn:panasonic-com:service:p00NetworkControl:1#X_SendKey"' \
-H "Content-Length: 200" \
-H 'Content-Type: text/xml;charset="utf-8"' \
-X POST --data <<-EOF
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <s:Body>
    <u:X_SendKey xmlns:u="urn:panasonic-com:service:p00NetworkControl:1">
      <X_KeyEvent>NRC_POWER-ONOFF</X_KeyEvent>
    </u:X_SendKey>
  </s:Body>
</s:Envelope>
EOF
http://192.168.1.87:55000/nrc/control_0/
I haven't tried this but you get the idea
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem running an Expect script within a Bash script mbeipi Programming 9 02-10-2018 05:00 AM
Problem with running bash script on open terminal window! gnome1919 Linux - Software 2 07-15-2014 07:02 AM
[SOLVED] Bash Script problem running If test on user entered variables Regnets1 Linux - Newbie 3 02-17-2012 02:21 PM
Problem running bash script recursively over a number of subdirectories using osx ghadley_00 Linux - Software 2 09-06-2011 10:38 AM
[SOLVED] Problem Running Bash Script in new Screen.. timdvtemp Programming 4 02-17-2011 07:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration