Bash

How to Run Linux cron Job at the End of Every Month

Edit /etc/crontab

vi /etc/crontab

Every end of the month

H 23 28-31 * * /usr/bin/test $( date -d '+1 day' +%d ) -eq 1 && <COMMAND>

Every last Friday of the month

0 0 * * 5 /usr/bin/test $( date +%m ) -ne $( date --date '7 day' +%m ) && <COMMAND>

These will be useful in Jenkins.

/usr/bin/test $( date -d '+1 day' +%d ) -eq 1

or

/usr/bin/test $( date +%m ) -ne $( date --date '7 day' +%m )
続きを読む

Bash: How to Show Escape Sequence Colors

Create the following script and run:

vi color.sh
chmod +x color.sh
./color.sh

The bash script:

#!/bin/bash

export txtrst='\x1b[00m'      # Reset

echo
for i in {0..255} ; do
  printf "\x1b[00;${i}m ${i}${txtrst}"
done
echo

echo
for i in {0..255} ; do
  printf "\x1b[38;05;%03dm 38;05;%03d " ${i} ${i}
  if [ $(( ${i} % 8 )) -eq 7 ] ; then
    echo
  fi
done
echo

Once you figure out the escape sequence color number, you can use as follows:

続きを読む

Linux: How to Change the Timezone

To adjust timezone on your Linux to Pacific Standard Time (PST/PDT), type the following on command line.

sudo mv /etc/localtime /etc/localtime.org; sudo ln -s /usr/share/zoneinfo/America/Los_Angeles /etc/localtime

To adjust timezone on your Linux to Japanese Standard Time (JST), type the following on command line.

sudo mv /etc/localtime /etc/localtime.org; sudo ln -s /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
続きを読む
Subscribe to Bash