Loading...
More Shell Posts
# Three ways of checking if a file exists in a shell scriptFILE=/etc/resolv.confif test -f "$FILE"; thenecho "$FILE exists."fiif [ -f "$FILE" ]; thenecho "$FILE exists."fiif [[ -f "$FILE" ]]; thenecho "$FILE exists."fi
#!/bin/bash# Turns 4 spaces into tabs.# Mostly stolen from AI# Define the directory to processDIRECTORY=$1TabCount=${2:-'4'} #Defaults to 4# Check if directory is specifiedif [ -z "$DIRECTORY" ]; thenecho "Error: Directory not specified."exit 1fi# Check if directory existsif [ ! -d "$DIRECTORY" ]; thenecho "Error: Directory does not exist."exit 1fi# Find all files in directory and subdirectoriesFILES=$(find "$DIRECTORY" -type f)# Loop through each file and unexpand itfor FILE in $FILES; dounexpand -t "$TabCount" "$FILE" > "$FILE.tmp"mv "$FILE.tmp" "$FILE"doneecho "Done!"
touch /tmp/login1.txt /tmp/login2.txtwhile [ true ]dowho | gawk '{ print $1 }' > /tmp/login2.txtcomm -13 /tmp/login1.txt /tmp/login2.txt#Just a bit easier to read#diff /tmp/login1.txt /tmp/login2.txtcat /tmp/login2.txt > /tmp/login1.txtsleep 1done
#!/bin/bash#Takes all the c and h files in the current directory and prints them#Yup, it's that easyfor file in *.h *.hpp *.c *.cpp; do#If it existsif [ -f "$file" ]; thenecho "//===============$file==============="cat $filefidone
#!/bin/bash#Originally made by Isaac Cook https://gist.github.com/icook/5400173#Modified by Leif Messinger#upload_key.sh [server_ip [server2_ip [...]]]#To be run locally on a linux computerif [ -e ~/.ssh/id_rsa.pub ];thenecho "SSH Key already exists on local machine"elseecho "Generating SSH key on local machine"ssh-keygen -t rsa #generates id_rsa and id_rsa.pubchmod -R 700 ~/.ssh #Sets permissions of ssh folderssh-add #Adds keys (and passwords?) to ssh_agent. (hopefully doesn't require password)fiecho "Loading client public key into memory"pubKey=$(<~/.ssh/id_rsa.pub)for serverdoecho "Adding client public key to $server remote server authorized keys"#Idiot Isaac Cook didn't know about ssh-copy-id#ssh-copy-id even checks if your key already exists#In fairness, I didn't either until researching ssh-addssh-copy-id -i ~/.ssh/id_rsa.pub $server #In theory, this should prompt for a username#ssh $server "mkdir -p ~/.ssh; #Make the folder if not already made# echo \"$pubKey\" >> ~/.ssh/authorized_keys; #Append your public key to the server's authorized_keys# chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys" #Set the correct permissions of those files#echo "Adding server public key to local authorized keys"#ssh $server "ssh-copy-id -i ~/.ssh/id_rsa.pub \$SSH_CLIENT" #this might need some awk, as $SSH_CLIENT spits out clientip portnumberecho "Displaying server public key"ssh $server "cat ~/.ssh/id_rsa.pub"#Though, he did give me a good ideaecho "Displaying keys authorized on $server (you can paste them in your authorized_keys file)"ssh $server "cat ~/.ssh/authorized_keys"#echo "Appending keys authorized on $server to your local authorized_keys"#ssh $server "cat ~/.ssh/authorized_keys" >> ~/.ssh/authorized_keysdoneecho "SSH keys schronized successfully!"
# ---------------- FIREWALL STEPS ----------------# Check if firewalld is installed and runningsudo systemctl status firewalld# If it's not running, you can start and enable itsudo systemctl start firewalldsudo systemctl enable firewalld# Add a rule to allow traffic on port 6006. Port 6006 is the default port that storybook runs on.sudo firewall-cmd --permanent --add-port=6006/tcp# Reload the firewall for the changes to take effectsudo firewall-cmd --reload# Check the list of allowed portssudo firewall-cmd --list-ports# ---------------- NGINX STEPS ----------------# Install Nginx (if not already installed)sudo yum install nginx# Start and enable Nginxsudo systemctl start nginxsudo systemctl enable nginx# Copy your storybook-static directory to a location that Nginx can serve from.# The default web root directory for Nginx is /usr/share/nginx/html.sudo cp -r /path/to/storybook-static /usr/share/nginx/html/# Adjust file permissions if needed to ensure that Nginx can read the filessudo chown -R nginx:nginx /usr/share/nginx/html/storybook-static# Put the following server block in /etc/nginx/conf.d/storybook.confserver {listen 6006;server_name your_domain.com;location / {root /usr/share/nginx/html/storybook-static;index index.html;}}# Test the Nginx configuration for syntax errorssudo nginx -t# If there are no errors, reload Nginx to apply the changessudo systemctl reload nginx