Here I get a querystring depending upon the value from the command shell_exec().  I am receiving a value the querystring but shell_exec() is not working.  I am using a webcam connected to Raspberry pi 3 so the command in shell_exec() is to turn the webcam ON an OFF.  $output=shell_exec('sudo /etc/init.d/motion start')   code:  &lt;?php $status=$_GET['status']; if($status == 'on') {     $output=shell_exec('sudo /etc/init.d/motion start'); } if($status == 'off') {     $output=shell_exec('sudo /etc/init.d/motion start'); }   How do I solve the execution issue?
23068
I need to run something as sudo without a password, so I used visudo and added this to my sudoers file:  MYUSERNAME ALL = NOPASSWD: /path/to/my/program   Then I tried it out:  $ sudo /path/to/my/program [sudo] password for MYUSERNAME:    Why does it ask for a password? How can I run/use commands as root with a non-root user, without asking for a password?
41942
I have the shell script  CONTROLLER_IP="" if [ "$#" -eq 1 ] then     CONTROLLER_IP=$1 else     echo "Usage : create_endpoint.sh --controller-ip &lt;Controller IP&gt;"     exit 1 fi   but its executing like this ./create_endpoint.sh 10.10.10.1   I want to execute like this /create_endpoint.sh --controller-ip 10.10.10.1
112227
Is there a standard Unix command that does something similar to my example below  $ &lt;cmd here&gt; 56 $ echo Return code was $? Return code was 56 $   &lt;cmd here&gt; should be something that can be fork-execed and leaves 56 as the exit code when the process exits. The exit and return shell builtins are unsuitable for what I'm looking for because they affect the invoking shell itself by exiting out of it. &lt;some cmd&gt; should be something that I can execute in non-shell contexts - e.g., invoking from a Python script with subprocess.  E.g., /usr/bin/false always exits immediately with return code 1, but I'd like to control exactly what that return code is. I could achieve the same results by writing my own wrapper script  $ cat my-wrapper-script.sh # i.e., &lt;some cmd&gt; = ./my-wrapper-script.sh #!/usr/bin/bash exit $1 $ ./my-wrapper-script.sh 56 $ echo $? 56   but I'm hoping there happens to exist a standard Unix command that can do this for me.
31437
In the Perl documentation,  suggests launching Perl scripts using a bilingual shell/Perl header:  #!/bin/sh #! -*-perl-*- eval 'exec perl -x -wS $0 ${1+"$@"}'     if 0;   What does ${1+"$@"} mean?  I tried using "$@" instead (using Bash as /bin/sh), and it seems to work just as well.    Edit  Two answers below say that it's supposed to be ${1:+"$@"}.  I am aware of the ${parameter:+word} ("Use Alternate Value") syntax documented in bash(1).  However, I am unconvinced, because   Both ${1+"$@"} and "$@" work just fine, even when there are no parameters.  If I create simple.sh as  #!/bin/sh eval 'exec /usr/bin/perl -x -S -- $0 "$@"'     if 0; #!perl use Data::Dumper; print Dumper(\@ARGV);   and question.sh as  #!/bin/sh eval 'exec /usr/bin/perl -x -S -- $0 ${1+"$@"}'     if 0; #!perl use Data::Dumper; print Dumper(\@ARGV);   I can get both to work identically:  $ ./question.sh  $VAR1 = []; $ ./question.sh a $VAR1 = [           'a'         ]; $ ./question.sh a 'b c' $VAR1 = [           'a',           'b c'         ]; $ ./question.sh "" $VAR1 = [           ''         ]; $ ./simple.sh  $VAR1 = []; $ ./simple.sh a $VAR1 = [           'a'         ]; $ ./simple.sh a 'b c' $VAR1 = [           'a',           'b c'         ]; $ ./simple.sh "" $VAR1 = [           ''         ];  Other sources on the Internet also use ${1+"$@"}, including  who seems to know what he's doing.   Perhaps ${parameter+word} is an undocumented alternate (or deprecated) syntax for ${parameter:+word}?  Could someone confirm that hypothesis?
96984
Consider the following script:  #!/bin/bash  set -o pipefail set -o history  trapper() {    func="$1" ; shift    for sig ; do       trap "$func $sig" "$sig"    done }  err_handler () {   case $2 in     INT)        stop_received=1     ;;     TSTP)     ;;     ERR)        if [[ $2 != "INT" ]]; then # for some reason, ERR gets triggered on SIGINT           code=$?           if [ $code -ne 0 ]; then              echo "Failed on line $1"              echo "$BASH_COMMAND returned $?"              echo "Content of variables at the time of failure:"              echo "$(set -o posix; set)"              exit 1           fi        fi     ;;   esac }  main() {    ping -c 5 www.google.com # this is a test to see if INT interrupts main()    # do a bunch of stuff, I mean a real bunch of stuff, like check some    # files, do some processing, connect to a database,    # do more processing, move some files around, you get the drift }  exec &gt; &gt;(tee -a my.log) exec 2&gt;&amp;1  trapper 'err_handler $LINENO' INT TSTP ERR while main do   if [[ "$stop_received" == "1" ]]; then      break   fi   setsid sleep 2 &amp; wait done trap ERR   What I am trying to accomplish is to run the script in an infinite loop until either the function main() returns some non zero value, i.e. some error occurred, or SIGINT is received.  However, I don't want SIGINT to stop main() from executing, in other words, if the script receives a SIGINT, it should wait for main() to finish, then exit nicely. But when I hit CTRL+C, I can see that ping is interrupted. At the moment I commented out everything under main() just to see if this works. Since ping gets interrupted, I am assuming other commands under main() would also get interrupted. When ping is interrupted, the processing jumps to the line where I check if $stop_received=1 and then the loop breaks and the script quits. If I replace the break with just an echo, then the script just continues on to the next iteration of the while main loop.  How can I stop SIGINT from interrupting the currently running command(s)? Since my script does a bunch of stuff, including DML statements in a database, interrupting main() would cause lot of grief.  Secondly, the script does not trap ctrl+z either. Or rather, the script just gets stuck on ctrl+z requiring a kill pid to terminate. I assumed that sleep being a child of bash as opposed to the script itself, ctrl+z would cause the script to pause, leaving sleep in limbo land. Hence the setsid and wait on sleep, but it still hangs.  thanks.
38093
Possible Duplicate:          I have a process which is basically a web-server, I start it during an SSH session. However, when I leave the session (by closing the PuTTY windows), it stops running and responding to requests. This is true even if I end the command with a &amp;. With Apache, I don't have this problem, it comes with a stop, a start, and a restart script. I'd like to create something like that for this program.  How can I start a process, so that it will continue running even after I end the SSH session I started it in? Also how can I set it to restart itself if it stops for some reason?  Thanks!
60484
how i can run this command from cmd :     powershell.exe "(get-process | ? {$_.Description -eq   "Sysinter Process Explorer"}) | select processname | out-file   $env:APPDATA\example.txt"   i still get this error :     You must provide a value expression on the right-hand side of the   '-eq' operato r. At line:1 char:37   + (get-process | ? {$_.Description -eq &lt;&lt;&lt;&lt;  Sysinternals Process Explorer}) | select processname | out-file $env:APPDATA\example.txt       + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordEx    ception       + FullyQualifiedErrorId : ExpectedValueExpression
23266
I just saw this in an init script: echo $&quot;Stopping Apache&quot;  What is that dollar-sign for? My research so far: I found this in the bash manual:  extquote  If set, $'string' and $&quot;string&quot; quoting is performed within ${parameter} expansions enclosed in double quotes.  This option is enabled by default.   ...but I'm not finding any difference between strings with and without the $ prefix: $ echo &quot;I am in $PWD&quot; I am in /var/shared/home/southworth/qed $ echo $&quot;I am in $PWD&quot; I am in /var/shared/home/southworth/qed $ echo $&quot;I am in ${PWD}&quot; I am in /var/shared/home/southworth/qed $ echo &quot;I am in ${PWD}&quot; I am in /var/shared/home/southworth/qed $ echo 'I am in ${PWD}' I am in ${PWD} $ echo $'I am in ${PWD}' I am in ${PWD} $ echo $'I am in $PWD' I am in $PWD
48283
I am taking the Linux Essentials class and was doing well until I hit the scripting chapter. I simply do not understand these concepts.  Wondering if someone can break the following down into ultra simplistic terms or point me to a better reference to learn it. I'm currently using netacad's curriculum.        From the text book (with minor formatting changes):     There are some special variables in addition to the ones you set. You   can pass arguments to your script:  #!/bin/bash echo "Hello $1"       A dollar sign followed by a number N corresponds to the Nth argument   passed to the script. If you call the example above with ./test.sh the   output will be Hello Linux. The $0 variable contains the name of the   script itself.      After a program runs, be it a binary or a script, it returns an exit   code which is an integer between 0 and 255. You can test this through   the $? variable to see if the previous command completed successfully.     I understand how to assign variables and how they work with the $ but the whole issue with $0 and $1 -- I just don't get it.    Any help would be much appreciated.
115643
If I just use basename {} .txt, it will work:  find . -iname "*.txt" -exec basename {} .txt \;   It will just print xxx instead of ./xxx.txt  if I want use $(basename {} .txt) in the -exec option, it will fail:  find . -iname "*.txt" -exec echo "$(basename {} .txt)" \;   It will just print ./xxx.txt  How can I solve this problem? I hope I can use $(basename {} .txt) as parameters for other cmd. Do I have to do sh -c or pipe -exec basename {} \; with xargs?
78919
I want to start a program with SSH using PHP, which works fine, but now I want to kill the screen with PHP, but the only thing I know is the name of the screen. How do I find out the screen ID (automatically)?
77200
Any idea why echo statement is being executed in both scenarios?  Outputs it worked:  #!/bin/bash  rizwan='' if [ -n $rizwan ]; then   echo "it worked" fi   Replace -n with -z, and it outputs it worked when expecting no output:  #!/bin/bash  rizwan='' if [ -z $rizwan ]; then   echo "it worked" fi
12595
I'm using find with the -exec option in console, on FreeBSD (for example, find . -exec sha1 {} \;).   How do I correctly place (and if needed, escape) redirect and other execution control symbols that could syntactically apply to either of the exec command or the find command, such as > >> | and &amp;, where I might want the symbol to apply to the find or the exec commands on different occasions?  On the same theme, what is the syntax if I want to use tee to view the output of the -exec commands on the console (to watch progress) and also appended to a file (for later use)?   (I know shells vary but hopefully the most used shells such as sh/csh are quite similar?)  Update:  In part, I want to learn if nested find -exec can be done without scripting, as a simple command. Here is the use-case that prompted the questio :   outer find: find all subdirs matching DIR_MATCH_TEXT in DIR1  inner find: for each matching subdir found in the outer loop (call it DIR2), execute the commandfind DIR2 -name "FILE_MATCH_TEXT" -exec sha1 {} \; &gt;&gt; DIR1/DIR2_hashes.txt   The aim being to create a set of files, one for each matching subdir, containing the output of some find -exec action on that subdir.  By this I mean that, if /backups contains /jan2017 and /feb2017, the result will be two files at /backups/jan2017_hashes.txt and /backups/feb2017_hashes.txt, with jan2017_hashes.txt containing the output from sha1 for (say) all .pdf files in /backups/jan2017, and feb2017_hashes.txt containing the output from sha1 for all .pdf files in /backups/feb2017.  From replies so far I gather the outer find would have to use a shell call as the argument to -exec?
42698
That is literal, {fd} isn't a placeholder. I have a script that does this, and does not source in anything, nor does it reference {fd} anywhere else.  Is this valid bash?  exec {fd}&lt;/dev/watchdog
108149
I want to use a variable from the main shell in a sub shell. I did:  export mysql_root_password="test" (     echo $mysql_root_password ) | dialog --gauge "Working hard..." 6 50   There is no output. Of course there is not since I send the output to dialog. Is there a way to output specific variables still the normal way without removing the dialog part?
100567
This is from . It's about executing a Perl script.     Finally, if you are unfortunate enough to be on an ancient Unix system   that doesn’t support the magic #! line, or if the path to your   interpreter is longer than 32 characters (a built-in limit on many   systems), you may be able to work around it like this:   #!/bin/sh -- # perl, to stop looping eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if 0;   Can you explain step by step what's going on here? I'm trying to make it work or encompass, but to no avail.  At execution of just the above, I'm getting this:  /bin/sh: 0: Illegal option --
27331
I looking into writing my own init.d scripts to control several services running on my Linux server. I came across an example online which contained:  nohup $EXEC_SCRIPT 0&lt;&amp;- &amp;&gt; $LOG_FILE &amp; echo $! &gt; $PID_FILE   From what I understand:   nohup Catches the hangup signal  $EXEC_SCRIPT is a variable containing the command to be run  0&lt;&amp;- &amp;&gt; Not come across this before $LOG_FILE similar to $EXEC_SCRIPT but contains the log file path &amp; starts logging to $LOG_FILE in the background? $! is the PID of the most last background command &gt; writes the result of $! to the $PID_FILE   I can work through it with this knowledge but the 0&lt;&amp;- &amp;&gt; is completely throwing me off. I don't like to include things that I don't at least partially understand first.