Get Days in a month from a bash script

Useful listing of days in a month to populate directories or run scripts for backing up getting the correct dates of days in a month and year.

 

 


YEAR=2020
MONTH=2

for DAY in $(DAYS=`cal $MONTH $YEAR | awk 'NF {DAYS = $NF}; END {print DAYS}'` && seq -f '%02G' $DAYS) ;do
DATE="$YEAR-$MONTH-$DAY"
echo $DATE
done

nJoy 😉

SYSTEMD – controls

Starting with Ubuntu 15.04, Upstart will be deprecated in favor of Systemd. With Systemd to manage the services we can do the following:

systemctl start SERVICE – Use it to start a service. Does not persist after reboot

systemctl stop SERVICE – Use it to stop a service. Does not persist after reboot

systemctl restart SERVICE – Use it to restart a service

systemctl reload SERVICE – If the service supports it, it will reload the config files related to it without interrupting any process that is using the service.

systemctl status SERVICE – Shows the status of a service. Tells whether a service is currently running.

systemctl enable SERVICE – Turns the service on, on the next reboot or on the next start event. It persists after reboot.

systemctl disable SERVICE – Turns the service off on the next reboot or on the next stop event. It persists after reboot.

systemctl is-enabled SERVICE – Check if a service is currently configured to start or not on the next reboot.

systemctl is-active SERVICE – Check if a service is currently active.

systemctl show SERVICE – Show all the information about the service.

sudo systemctl mask SERVICE – Completely disable a service by linking it to /dev/null; you cannot start the service manually or enable the service.

sudo systemctl unmask SERVICE – Removes the link to /dev/null and restores the ability to enable and or manually start the service.

Just copied notes. 😉 nJoy

Automatically passing ssh password in scripts especially to ESX where passwordless ssh is hard

First you need to install sshpass.

  • Ubuntu/Debian: apt-get install sshpass
  • Fedora/CentOS: yum install sshpass
  • Arch: pacman -S sshpass

Example:

sshpass -p "YOUR_PASSWORD" ssh -o StrictHostKeyChecking=no YOUR_USERNAME@SOME_SITE.COM

Custom port example:

sshpass -p "YOUR_PASSWORD" ssh -o StrictHostKeyChecking=no YOUR_USERNAME@SOME_SITE.COM:2400

from : https://stackoverflow.com/questions/12202587/automatically-enter-ssh-password-with-script

 

This works better for me though for sshfs:

echo $mypassword | sshfs -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no user@host mountpoint -o workaround=rename -o password_stdin 

 

 

nJoy 😉

 

fail to mount ntfs in BSD

[root@ftp /mnt/test]# ntfs-3g /dev/da10s1 /mnt/test                                                                                 
fuse: failed to open fuse device: No such file or directory 

kldload fuse  

That’s a missing module needs loading.
nJoy 😉

Resizing a disk once the volume has grown on host in a VM (Ubuntu)

The disk will not automatically resize on many platforms once more disk space was made available.

Particularly in Ubuntu 16.04

Rescanning the device for size maps :

echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan

Then standard procedures to grow the fs apply.

nJoy 😉

 

 

Longevity and stability of sshfs

Just worth noting

I had many arguments with other sysadmins and bosses over the stability and validity of sshfs as a shortcut to creating a bridge for transferring files for backup or adhoc moves

 

The following is the result of an rsync from one sshfs mount to another (from ESXi servers I only had ssh access to )  over a slow link surpassed my expectations, by far:

 

sent 1342341123955 bytes  received 91 bytes  3495447.89 bytes/sec 

total size is 1342177283599  speedup is 1.00

 

Yes 1.3TB VM image taken with GhettoVCB moved over the arch of about 4.4 days with no loss or corruption.

 

Amazing…

Just worth saying in Linux where there is a will there is a way. In Windows the same move was dying out and never recovering, we tried simple file copy using the vmware browser download, veem ( gave up the move for some wierd licensing reason) , robocopy  you name it.

Solution :

 

mount both servers to a vm over ssh using sshfs and rsync across. The process was slow for the following reasons:

  1. The lack of compression.
  2. Encryption on both tunnels across ( ssh )
  3. VMware expanding the image as it is pulled from the VMFS (as it does)
  4. Network badwidth is slow and shared with literally hundreds of machines
  5. Some other reasons like disk latency ( no cache on the controller) etc..

 

I am just saying sometime even relatively inelegant solutions can give surprising results in Linux environments.

Ode to stability and the fortune of having such amazing free tools to work with.

 

🙂

 

 

 

 

Using ngrok with React based websites

The problem :

When we have a react.js based site (hosted on port 8000) and ngrok it for development purposes we get

Invalid Host Header 

The fix is to override the header on reflection:

ngrok http 8000 -host-header="localhost:8000"

 

That’s it

😉 nJoy