Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# Create SFTP User
## This script will create the account with read-only permissions which helps us to give the user download-only files. Along with that we give a directory "uploads" that is present inside the user's home and can be used for uploading whichis having read-write access for this user.
echo "========================================================================================================================"
echo " SFTP account creation. The home dir will be read-only, for write access the user should use "uploads" directory in home."
echo "========================================================================================================================"
# Input username and the number of days that the user will be active. Only enter the "username" and "number" of days.
@cejojohn
cejojohn / RemoveSpace
Last active August 12, 2016 12:46
Deleting blank spaces from files. I used it along with my scripts to configure the rsyslog server. I was provided with a jumbled list of more than hundred network switches.
#!/bin/bash
#To delete all whitespace: cat file.txt | tr -d "[:space:]"
#To delete all horizontal whitespace: cat file.txt | tr -d "[:blank:]"
#Using LibreOffice calc in the final stage I had two columns to merge. Eg:
/var/log/Switches/ Switch1
/var/log/Switches/ Switch2
. .
. .
. .
@cejojohn
cejojohn / Append_Line-end
Last active August 12, 2016 12:45
Append characters at the end of each line. You can also append characters like new line or carriage return. I used in rsyslog configurations where I had scripted and created a set of remote syslog reception for a set of switches and needed the add the ending character for the if condition of syslog.
#!/bin/bash
sed -e 's/$/string after each line/' -i filename
#So for me I needed to add "& ~" at the end of all lines in my file so that I could copy it to rsyslog.conf to receive logs from the network devices.
#Initial File:
if $fromhost-ip == '1.1.1.1' then /var/log/Switches/Switch1.log
if $fromhost-ip == '2.2.2.2' then /var/log/Switches/Switch2.log
. . . . . .
. . . . . .
. . . . . .
pass='YOURPASSWORD'
for host in `cat ips`
do
sshpass -p $pass ssh -o ConnectTimeout=1 -o StrictHostKeyChecking=no -o GSSAPIAuthentication=no root@$host "hostname"
done
### Using encoding to escape Shoulder Surfing ;)
vim tempfile
#In the file write your password
cat tempfile | openssl enc -base64