Help with exec

I figure I’m doing something basic wrong.
I have this php code.

$cmd = “at $wtime $wdate <<< “sftp -a -r -P xxx [email protected]:”.$file.” /mnt/TRFR “” ;
exec ("$cmd");
echo $cmd;

the “at” command is never generated atq returns blank. But if I copy the output of the echo from the web page into bash the “at” job gets created.

Why are you quoting the variable?

Is that the issue? It’s my understanding that’s how exec works. Ok removing the quotes did nothing. Still the same.

It’s entirely possible due to the unsafe nature of the command, that it is turned off.

Try this one in place of, passthru()

Same result with “passthru”. This has me stumped.

I guess the next question would how do you plan on calling this? If it is a timed thing, you could use a bash script for a cron job

I don’t understand “at” is the timing. at is a command in linux.

SOLVED it’s not pretty but it works.

The issue was that PHP runs /bin/sh as it’s shell NOT bash ! /bin/sh is just a link to /bin/dash never heard of dash!
So I changed the link for /bin/sh to link to /bin/bash then modified my code to this:
$cmd = ““at $wtime $wdate <<< ‘sftp -a -r -P xxx [email protected]:’$file” /mnt/TRFR”"" ;
exec ("/bin/bash -c $cmd");
echo $cmd;

the -c is necessary.

Figuring out where to put single quotes, double quotes and what quotes to escape was the tricky bit after getting php to use bash in stead of dash.
dash it appears has no concept of <<<

exec ("/bin/bash -c $cmd"); <---- This does not work by itself. The command was still being executed by sh:
/bin/sh link still had to be changed to /bin/bash
I have now discovered why this is so. Regardless “at” executes all commands with /bin/sh so to get the <<< redirect to work I had to link /bin/sh to bash instead of dash as dash has no concept of <<<

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service