0

I have a PHP script that controls VLC player. My script interacts with VLC to pause, play, and get_time.

It works perfectly if I run it as my user on the terminal (without sudo or anything) in Ubuntu 14.04.

I have it running under my user's Cron to check if there's a showtime every minute.

When it runs as Cron, it can't control VLC, so the video file just starts playing and I have no idea how far in it is to run my other commands properly.

I think this is because VLC should be playing in /bin/bash. When I set that in my Cron file, it changes the shell to /bin/bash (which I can verify has changed in PHP's $_ENV variable).

How can I make the Cron environment for my user run identically to the command line as my user?

This is the PHP script that works from the terminal:

$desc = array(
    0 => array('pipe', 'r'), // 0 is STDIN for process
    1 => array('pipe', 'w'), // 1 is STDOUT for process
    2 => array('file', '/movie_log.txt', 'a') // 2 is STDERR for process
);

$cmd = 'vlc --fullscreen --no-video-title --play-and-exit --x11-display :0 /videos/whatever_movie_file.mp4';
$p = proc_open($cmd, $desc, $pipes);

stream_set_blocking($pipes[0], 0);
stream_set_blocking($pipes[1], 0);

$p_status = proc_get_status($p);

$stream = stream_get_contents($pipes[1]);
usleep(500000);

fwrite($pipes[0], 'pause'.PHP_EOL);
usleep(250000);

$stream = stream_get_contents($pipes[1]);

fwrite($pipes[0], 'get_time'.PHP_EOL);
usleep(250000);

$stream = stream_get_contents($pipes[1]);

This is my local user's Cron file:

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/u$

*/1 * * * * php /usr/share/nginx/html/includes/projectionist.cron.php

This is PHP's $_ENV output from terminal:

[XDG_SESSION_ID] => 1
[TERM] => xterm-256color
[SHELL] => /bin/bash
[SSH_CLIENT] => 192.168.1.120 62103 22
[GTK_MODULES] => pantheon-filechooser-module
[SSH_TTY] => /dev/pts/1
[USER] => grandcameo
[LS_COLORS] => rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
[MAIL] => /var/mail/grandcameo
[PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
[PWD] => /home/grandcameo
[LANG] => en_CA.UTF-8
[SHLVL] => 1
[HOME] => /home/grandcameo
[LANGUAGE] => en_CA:en
[LOGNAME] => grandcameo
[SSH_CONNECTION] => 192.168.1.120 62103 192.168.1.121 22
[LESSOPEN] => | /usr/bin/lesspipe %s
[GTK_CSD] => 1
[XDG_RUNTIME_DIR] => /run/user/1000
[LESSCLOSE] => /usr/bin/lesspipe %s %s
[_] => /usr/bin/php

And this is PHP's $_ENV output from Cron:

[SHELL] => /bin/bash
[PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
[PWD] => /home/grandcameo
[LANG] => en_CA.UTF-8
[SHLVL] => 1
[HOME] => /home/grandcameo
[LANGUAGE] => en_CA:en
[LOGNAME] => grandcameo
[_] => /usr/bin/php
user1721724
  • 89
  • 1
  • 2
  • 11
  • Updating question with code. – user1721724 Dec 17 '15 at 15:23
  • Perhaps this: http://stackoverflow.com/questions/20288822/environment-is-not-passed-to-process-opened-by-proc-open – Progrock Dec 17 '15 at 16:05
  • OK, I'm going to try this right away. Will this make a difference even if VLC still runs without the full path? The problem is my pipes with VLC are always empty in Cron, so I can tell it what to do or find out how far it's in, but the pipes are populated and those commands work in terminal. – user1721724 Dec 17 '15 at 16:06
  • Already found that question and set my variable_options accordingly. – user1721724 Dec 17 '15 at 16:07
  • I also manually set all the variables to match the terminal variables at the top of the Cron file. Now the $_ENV output matches, but I still have empty pipes to control VLC with. – user1721724 Dec 17 '15 at 16:08

0 Answers0