This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
средства_программирования_shell [2024/06/19 09:05] val [Использование диалоговых окон] |
средства_программирования_shell [2025/03/10 10:06] (current) val [Передача сообщений в syslog] |
||
---|---|---|---|
Line 192: | Line 192: | ||
<code> | <code> | ||
- | $ cat log_gen.sh | + | bash -c 'cat <<END >log_gen.sh |
- | </code><code> | + | |
while : | while : | ||
do | do | ||
Line 199: | Line 198: | ||
logger -t cisco -p local0.info "Message 2" | logger -t cisco -p local0.info "Message 2" | ||
done | done | ||
+ | END' | ||
</code><code> | </code><code> | ||
- | $ sh cisco_log_gen.sh | + | $ sh log_gen.sh |
</code> | </code> | ||
===== Примеры использования скриптов sh в системах загрузки ===== | ===== Примеры использования скриптов sh в системах загрузки ===== | ||
Line 418: | Line 418: | ||
# echo `date` OK $filename on `hostname` >> $log | # echo `date` OK $filename on `hostname` >> $log | ||
echo -e "HTTP/1.1 200 OK\r" | echo -e "HTTP/1.1 200 OK\r" | ||
- | echo -e "Content-Type: $(/usr/bin/file -bi $filename)\r" | + | echo -e "Content-Type: $(/usr/bin/file -bi "$filename")\r" |
echo -e "\r" | echo -e "\r" | ||
/bin/cat "$filename" | /bin/cat "$filename" | ||
else | else | ||
- | # echo "$(date)" ERR $filename on "$(hostname)" >> "$log" | + | # echo "$(date)" ERR "$filename" on "$(hostname)" >> "$log" |
echo -e "HTTP/1.1 404 Not Found\r" | echo -e "HTTP/1.1 404 Not Found\r" | ||
echo -e "Content-Type: text/html;\r" | echo -e "Content-Type: text/html;\r" | ||
Line 438: | Line 438: | ||
==== Ресурсы Web сервера на shell ==== | ==== Ресурсы Web сервера на shell ==== | ||
<code> | <code> | ||
- | # mkdir /var/www | + | # mkdir -p /var/www |
# cat /var/www/index.html | # cat /var/www/index.html | ||
Line 447: | Line 447: | ||
</html> | </html> | ||
</code><code> | </code><code> | ||
- | # mkdir /var/www/img | + | # mkdir -p /var/www/img |
</code> | </code> | ||
Line 470: | Line 470: | ||
<code> | <code> | ||
- | $ cat mail.bash | + | $ cat mail.sh |
</code><code> | </code><code> | ||
- | #!/bin/bash | + | #!/bin/sh |
+ | |||
+ | [ -f "$1" ] || { echo Example: ./mail.sh attach_file_name; exit 1; } | ||
EMAIL="val@bmstu.ru" | EMAIL="val@bmstu.ru" | ||
MAILSERVER="mailhub.bmstu.ru" | MAILSERVER="mailhub.bmstu.ru" | ||
- | + | FILENAME=$1 | |
- | [ -f "$1" ] || { echo Example: ./mail.bash attach_file_name; exit 1; } | + | |
{ | { | ||
- | sleep 5; | + | sleep 2; |
- | echo "EHLO $MAILSERVER"; | + | echo "EHLO $MAILSERVER"; sleep 1; |
- | sleep 3; | + | echo "MAIL FROM: <$EMAIL>"; sleep 1; |
- | echo "MAIL FROM: <$EMAIL>"; | + | echo "RCPT TO: <$EMAIL>"; sleep 1; |
- | sleep 3; | + | echo "DATA"; sleep 1; |
- | echo "RCPT TO: <$EMAIL>"; | + | echo "To: $EMAIL" |
- | sleep 3; | + | echo "Subject: $FILENAME" |
- | echo "DATA"; | + | echo "MIME-Version: 1.0 (mime-construct 1.9)" |
- | sleep 3; | + | echo "Content-Type: $(/usr/bin/file -bi $FILENAME); name=\"$FILENAME\"" |
- | echo -e "To:$EMAIL\nSubject: $1\nMIME-Version: 1.0 (mime-construct 1.9)\nContent-Type: $(/usr/bin/file -bi $1); name=\"$1\"\nContent-Transfer-Encoding: base64\n\n"; | + | echo "Content-Transfer-Encoding: base64"; |
- | cat $1 | openssl base64; | + | echo |
+ | cat $FILENAME | openssl base64; | ||
echo '.'; | echo '.'; | ||
- | echo -e "QUIT\n\n"; | + | echo "QUIT"; |
+ | echo | ||
} | nc $MAILSERVER 25 | } | nc $MAILSERVER 25 | ||
- | |||
</code> | </code> | ||