GCloud Interactive Shell

If you already have Google SDK installed, you can activate GCloud Interactive Shell, which is still in beta by the way, by typing the following command from the Google SDK terminal.

gcloud beta interactive

The interactive shell environment has auto-completion. It shows you who’s logged in and which project you are currently set in. To exit the interactive shell, just Press F9 to quit.

Run Shell Script From Your Website

Here’s how to run a shell script from your website. You’ll need 2 files.

Here’s the contents of foo.php. Wrap your output with ‘pre’ for better formatting.

$output = shell_exec('/var/www/html/bar.sh 2>&1');
echo "$output";

Here’s the content of bar.sh. Output will be displayed on web page.

now="$(date +'%y%m%d')"
echo $now
aws s3 ls

Bash Source in Cron

I’m running a “source” command inside a Bash script. The script is running fine on its own, but when I try running it inside a crontab, it doesn’t work. I’m using the source command just to load variables in a file, so I don’t have to edit multiple files. As it turns out, the regular shell in crontab does not quite understand the source command, and it’s the very reason the script fails. Here’s an example.

source /home/user/server.conf

I ended up removing the source line, and hardcoding the variables instead of loading it from a file.