Uly.me

cloud engineer

  • Home
  • About
  • Archives
Home/Archives for shell

June 16, 2020

Linux Useradd

Here’s the command to add a Linux user.

useradd -m -s $(which bash) -G sudo ulysses

useradd -m -s $(which bash) -G sudo ulysses

-m creates a home directory. -s selects a shell. -G adds user to a sudo group.

September 21, 2019

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

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.

September 10, 2019

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.

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

<?php $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.

#!/bin/bash
now="$(date +'%y%m%d')"
echo $now
aws s3 ls

#!/bin/bash now="$(date +'%y%m%d')" echo $now aws s3 ls

June 23, 2019

Which shell is running

Here’s how to find out which shell you are running. Run any of the 3 commands below.

echo $0
echo $SHELL
ps -p "$$"

echo $0 echo $SHELL ps -p "$$"

December 16, 2018

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

source /home/user/server.conf

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

server="servername"

server="servername"

  • Cloud
  • Linux
  • Git

Copyright © 2012–2021