Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d3b8b45f5a | |||
| 35a25084c7 | |||
| 47d036941e |
@@ -0,0 +1,9 @@
|
||||
install:
|
||||
cp screxec /usr/bin/screxec && chmod 755 /usr/bin/screxec
|
||||
cp scrstart /usr/bin/scrstart && chmod 755 /usr/bin/scrstart
|
||||
cp screwrite /usr/bin/screwrite && chmod 755 /usr/bin/screwrite
|
||||
|
||||
clean:
|
||||
rm /usr/bin/screxec
|
||||
rm /usr/bin/scrstart
|
||||
rm /usr/bin/screwrite
|
||||
@@ -1,3 +1,3 @@
|
||||
# Linux Hacks / Scripting
|
||||
# Screen tools
|
||||
|
||||
This repository serves as a general place for archiving various GNU/Linux / GNU/BASH scripts, automations and installers.
|
||||
Screen tools suite is designed for "screen" only as it is terminal-only alternative to SuperPutty.
|
||||
@@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
# get all elements and append domain to them. Then output to file
|
||||
|
||||
write_ip() {
|
||||
for ip_in in $2
|
||||
do
|
||||
echo "$ip_in" >> $1
|
||||
done
|
||||
}
|
||||
|
||||
write_fqdn() {
|
||||
for host_in in $3
|
||||
do
|
||||
echo "$host_in.$1" >> $2
|
||||
done
|
||||
}
|
||||
|
||||
if [ -z $1 ]
|
||||
then
|
||||
echo -e "Usage:\n\
|
||||
screwrite <FQDN.here.com> <file_to_insert_into> host1 host2.... hostN\n\
|
||||
screwrite --ip <file_to_insert_into> ip_1 ip2... ipN\n\
|
||||
screwrite erase <file_to_erase>"
|
||||
elif [[ $1 == 'erase' ]]
|
||||
then
|
||||
if [ -z $2 ]
|
||||
then
|
||||
echo "Supply file name to erase or create."
|
||||
else
|
||||
echo '' > $2
|
||||
fi
|
||||
else
|
||||
if [[ $1 == 'ip' ]]
|
||||
then
|
||||
FILE=$2
|
||||
shift
|
||||
shift
|
||||
write_ip $FILE $@
|
||||
else
|
||||
FQDN=$1
|
||||
FILE=$2
|
||||
shift
|
||||
shift
|
||||
write_fqdn $FQDN $FILE $@
|
||||
fi
|
||||
fi
|
||||
@@ -0,0 +1,87 @@
|
||||
#!/bin/bash
|
||||
|
||||
function screkill() {
|
||||
for inc in `ps -aux | grep SCREEN | grep -v grep | awk '{print $2}'`
|
||||
do
|
||||
kill $inc
|
||||
done
|
||||
}
|
||||
|
||||
function execute() {
|
||||
screen -S "$1" -p 0 -X stuff "$2"$(echo -ne '\015')
|
||||
}
|
||||
|
||||
function listall() {
|
||||
screen -r $1
|
||||
}
|
||||
|
||||
function send_esc() {
|
||||
screen -S "$1" -X stuff $(echo -ne '\033')
|
||||
}
|
||||
|
||||
|
||||
sort_list() {
|
||||
screen -ls | cut -d '.' -f2- | sort
|
||||
}
|
||||
|
||||
function list_source() {
|
||||
if [ "$2" == 'nofile' ]
|
||||
then
|
||||
grep `echo "$1" | cut -d '.' -f2-` -r ./ | sed -s 's/:/\t/g' | sed -s 's/\.\///g' | awk '{print $2}'
|
||||
else
|
||||
grep `echo "$1" | cut -d '.' -f2-` -r ./ | sed -s 's/:/\t/g' | sed -s 's/\.\///g'
|
||||
fi
|
||||
}
|
||||
|
||||
# $1 = server, $2 = file_to_read_from, $3 = command itself
|
||||
function exec_of() {
|
||||
grep `echo "$1" | cut -d"." -f2-` "$2" >> /dev/null
|
||||
if [ $? == 0 ]
|
||||
then
|
||||
# echo "$3"
|
||||
# echo "server: $1"
|
||||
execute "$1" "$3"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
function loop() {
|
||||
for server in `screen -ls | grep Detached | sort | awk '{print $1}'`
|
||||
do
|
||||
if [ "$1" == 'listall' ]
|
||||
then
|
||||
listall "$server"
|
||||
elif [ "$1" == 'src' ]
|
||||
then
|
||||
list_source "$server" "$2"
|
||||
elif [ "$1" == 'execof' ]
|
||||
then
|
||||
exec_of "$server" "$2" "$3"
|
||||
elif [ "$1" == 'esc' ]
|
||||
then
|
||||
send_esc $server
|
||||
else
|
||||
execute "$server" "$1"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
if [ "$1" == 'killall' ]
|
||||
then
|
||||
screkill
|
||||
elif [ -z "$1" ]
|
||||
then
|
||||
echo -e "Usage:\n\
|
||||
Execute a command:\t\t\tscrexec '<command in single quotes>'\n\
|
||||
Switch to all sessions:\t\tscrexec listall\n\
|
||||
List running servers:\t\tscrexec src\n\
|
||||
Run on sessions from file:\t\tscrexec execof <file_here> '<command in quotes>'"a
|
||||
elif [ "$1" == 'SACT' ]
|
||||
then
|
||||
send_sact
|
||||
elif [ "$1" == "sort" ]
|
||||
then
|
||||
sort_list
|
||||
else
|
||||
loop "$@"
|
||||
fi
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
connect() {
|
||||
for server in `cat $1 | awk '{print $1}'`
|
||||
do
|
||||
screen -d -m -S "$server-$1" ssh "$2@$server" -oStrictHostKeyChecking=no -i $3
|
||||
done
|
||||
}
|
||||
|
||||
wakeup() {
|
||||
for hwaddr in `cat $1 | awk '{print $2}'`
|
||||
do
|
||||
etherwake $hwaddr
|
||||
done
|
||||
}
|
||||
|
||||
if [ -z $1 ]
|
||||
then
|
||||
echo -e "Usage for direct SSH:\tscrstart <file_to_read_from> <user> <key | password>"
|
||||
echo -e "Usage for waking up machines:\tscrstart <file_to_read_from> wakeup"
|
||||
else
|
||||
if [[ $2 == "wakeup" ]]
|
||||
then
|
||||
wakeup $1
|
||||
else
|
||||
connect $1 $2 $3
|
||||
fi
|
||||
fi
|
||||
Reference in New Issue
Block a user