Remove part of path on Unix

If you wanted to remove a certain NUMBER of path components, you should use cut with -d”https://stackoverflow.com/”. For example, if path=/home/dude/some/deepish/dir: To remove the first two components: # (Add 2 to the number of components to remove to get the value to pass to -f) echo $path | cut -d”https://stackoverflow.com/” -f4- # output: # some/deepish/dir … Read more

Automate scp file transfer using a shell script

Instead of hardcoding password in a shell script, use SSH keys, its easier and secure. $ scp -i ~/.ssh/id_rsa *.derp devops@myserver.org:/path/to/target/directory/ assuming your private key is at ~/.ssh/id_rsa and the files you want to send can be filtered with *.derp To generate a public / private key pair : $ ssh-keygen -t rsa The above … Read more

How can I execute a command stored in a variable?

Unix shells operate a series of transformations on each line of input before executing them. For most shells it looks something like this (taken from the Bash man page): initial word splitting brace expansion tilde expansion parameter, variable and arithmetic expansion command substitution secondary word splitting path expansion (aka globbing) quote removal Using $cmd directly … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)