move dirs
This commit is contained in:
5
code/Bash/README.md
Normal file
5
code/Bash/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Bash & Unix Shell
|
||||
|
||||
* [UnixSocket сервер на `nc`](unix-socket-server.sh)
|
||||
* [Проверка наличия команды](command_exists.s)
|
||||
* [Проверка наличия файла/директории](file_folder_exists.sh)
|
14
code/Bash/command_exists.sh
Normal file
14
code/Bash/command_exists.sh
Normal file
@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
if ! [ -x "$(command -v git)" ]; then
|
||||
echo 'Error: git is not installed.' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# OR
|
||||
|
||||
if ! command -v crystal &> /dev/null
|
||||
then
|
||||
echo "<the_command> could not be found"
|
||||
exit
|
||||
fi
|
25
code/Bash/file_folder_exists.sh
Normal file
25
code/Bash/file_folder_exists.sh
Normal file
@ -0,0 +1,25 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Check file exists
|
||||
FILE=/etc/resolv.conf
|
||||
|
||||
if [ -f "$FILE" ]; then
|
||||
echo "$FILE exists."
|
||||
else
|
||||
echo "$FILE does not exist."
|
||||
fi
|
||||
|
||||
# OR
|
||||
|
||||
[ -f /etc/resolv.conf ] && echo "/etc/resolv.conf exists."
|
||||
|
||||
# Check directory exists
|
||||
DIR=/etc/docker
|
||||
|
||||
if [ -d "$DIR" ]; then
|
||||
echo "$DIR is a directory."
|
||||
fi
|
||||
|
||||
# OR
|
||||
|
||||
[ -d /etc/docker ] && echo "/etc/docker is a directory."
|
29
code/Bash/irc_logger.sh
Executable file
29
code/Bash/irc_logger.sh
Executable file
@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
# TODO: Добавить описание
|
||||
# TODO: Добавить в README.md
|
||||
|
||||
# https://linuxconcept.com/making-a-simple-irc-chat-bot-logger-using-bash-script/
|
||||
|
||||
nick="blb$$"
|
||||
channel=admin
|
||||
server=iiiypuk.me
|
||||
config=/tmp/irclog
|
||||
[ -n "$1" ] && channel=$1
|
||||
[ -n "$2" ] && server=$2
|
||||
config="${config}_${channel}"
|
||||
echo "NICK $nick" > $config
|
||||
echo "USER $nick +i * :$0" >> $config
|
||||
echo "JOIN #$channel" >> $config
|
||||
trap "rm -f $config;exit 0" INT TERM EXIT
|
||||
tail -f $config | nc $server 6667 | while read MESSAGE
|
||||
do
|
||||
case "$MESSAGE" in
|
||||
PING*) echo "PONG${MESSAGE#PING}" >> $config;; *QUIT*) ;;
|
||||
*PART*) ;;
|
||||
*JOIN*) ;;
|
||||
*NICK*) ;;
|
||||
*PRIVMSG*) echo "${MESSAGE}" | sed -nr "s/^:([^!]+).*PRIVMSG[^:]+:(.*)/[$(date '+%R')] \1> \2/p" >> $config;;
|
||||
*) echo "${MESSAGE}";;
|
||||
esac
|
||||
done
|
19
code/Bash/unix-socket-server.sh
Executable file
19
code/Bash/unix-socket-server.sh
Executable file
@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
# TODO: Добавить описание и пример работы
|
||||
|
||||
# TCP
|
||||
# coproc nc -l localhost 3000
|
||||
|
||||
# UnixSocket
|
||||
coproc nc -l -U ./app.sock
|
||||
|
||||
while read -r cmd; do
|
||||
case $cmd in
|
||||
d) date ;;
|
||||
q) break ;;
|
||||
*) echo 'Try again?'
|
||||
esac
|
||||
done <&"${COPROC[0]}" >&"${COPROC[1]}"
|
||||
|
||||
kill "$COPROC_PID"
|
Reference in New Issue
Block a user