bash snippits
A collection of misc bash snippits for my own memory.
# Converting all files in a directory to unix EOL markers
find . -type f -print0 -name '*.ext' | xargs -0 dos2unix
APF firewall
# Modify ports:
vim /etc/apf/conf.apf
# Restart a service (eg apf firewall) using systemctl
/bin/systemctl {start | stop | restart} apf
SSH
# General new public/private keys. Creates:
# ~/.ssh/id_rsa (PRIVATE)
# ~/.ssh/id_rsa.pub
ssh-keygen
# Display fingerprint
ssh-keygen -l
# Copy to a remote machine w/ existing access
ssh-copy-id user@remotehost
# Key can be manually registered on a remote machine by
# manually appending to ~/.ssh/authorized_keys (1 line per key)
echo public_key >> ~/.ssh/authorized_keys
PM2
A process manager for node.js applications.
# Show status of running jobs
pm2 status
# Start a job
# --watch to auto-restart
# --time to log timestamps (call also be added to restart)
pm2 start dist/index.js --name my-job
# Restart a job
pm2 restart my-job
# Show a terminal status ui
pm2 monit
# Show logs for a particular job
pm2 logs my-job --lines 1000 --timestamp
# Generate a startup script for server
# PM2 will auto-restart if the job crashes... but if the
# server restarts, PM2 will not and will not restart the jobs.
# This can be fixed by installing a startup script that will
# register PM2 as a system service. Run this command then copy
# and run the resulting command.
pm2 startup
# Deletes an a job. Accepts id if case duplicate jobs
pm2 delete job_name
# Show details for the job
pm2 describe
# Set an env variable
NODE_ENV=true pm2 restart my-job --update-env