#!/bin/bash
# Создаем шаблон конфига из скрипта (без использования массива)
cat > ./syslog-template <<"EOF"
/var/log/syslog
{
rotate 10
size 10M
daily
missingok
copytruncate
notifempty
compress
delaycompress
sharedscripts
postrotate
invoke-rc.d syslog-ng reload > /dev/null
endscript
}
EOF
# Удаляем секцию из файла
sudo sed -i '/\/var\/log\/syslog/,/}/d' /etc/logrotate.d/syslog-ng
# Добавляем секцию в файл
# Тут, возможно, надо будет " | sudo tee -a" вместо пайпа
cat ./syslog-template >> /etc/logrotate.d/syslog-ng
# ^-- Вот эту команду можно совместить с первой, чтобы не создавать лишний файл
#!/bin/bash
# На момент вызова файл шаблона должен существовать
ORIGINAL=$(cat ./syslog-template)
EXISTING=$(sed -rne '/\/var\/log\/syslog/,/}/p' /etc/logrotate.d/syslog-ng)
[[ "$ORIGINAL" == "$EXISTING" ]] && echo "файл настроен" || echo "файл не настроен"
#!/bin/bash
select site in $(jq -r '.sites[].title' sites.json)
do
select area in "admin" "front"
do
# get links for "area"
links=$(jq '.sites[] | select(.title == "'${site}'") | .'${area}' |.[]' sites.json)
# here you can do whatever you want - iterate through links, opening them with xdg-open, or just print them out
echo $links
break
done
break;
done
select area in "admin" "front"
select area in $(jq -r '.sites[] | select(.title == "'${site}'") | keys | .[] | select(. != "title")' sites.json)
#!/bin/bash
octets=({0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1})
addrtobin(){
for digit in ${1//./ }; do echo -n ${octets[digit]}; done
}
# Просто пример для списков адресов и сетей.
# Лучше используйте exec N<>filename.txt + read -u N
ips=$(cat ips.txt)
nets=$(cat nets.txt)
for ip in $ips
do
out=1
bin_ip=$(addrtobin $ip)
for net in $nets
do
bin_net=$(addrtobin ${net%%/*})
net_mask=${net#*/}
if [ "${bin_ip:1:$net_mask}" == "${bin_net:1:$net_mask}" ]
then
out=0
break # Чтобы не проходить до конца списка сетей, если адрес уже найден
fi
done
[ $out -eq 1 ] && echo $ip
done
read b
case $b in
1) clear ; ./1_1_system_menu.sh && exit; unem ;;
2) clear; ./1_1_ipmi_menu.sh && exit; unem ;;
3) clear ; menu ;;
0) exit 0 ;;
esac
#!/bin/bash
# Insert necessary sub-menus
. ./ipmi_menu.sh
declare -A MAINITEMS
MAINITEMS['System settings']="echo 'System settings selected'"
MAINITEMS['Ipmi tools']="PMI"
MAINITEMS['Back to previous']="break"
MAINITEMS['Exit']="exit"
while :
do
select menuitem in "${!MAINITEMS[@]}"
do
echo "Menu item: $menuitem"
${MAINITEMS[$menuitem]}
done
done
#!/bin/bash
PMI(){
echo "PMI functions"
PMI_TITLES=(\
"Sensors check" \
"Writing Motherboard FRU information"\
"Writing MAC address BMC"\
"Wtiting MAC address Motherboard"\
"Back to previous"\
"Exit")
PMIITEMS[1]="echo Sensors check"
PMIITEMS[2]="echo fru information"
PMIITEMS[3]="echo mac address"
PMIITEMS[4]="echo mac address motherboard"
PMIITEMS[5]="break"
PMIITEMS[6]="exit"
select pmiitem in "${PMI_TITLES[@]}"
do
${PMIITEMS[$REPLY]}
done
}
install_timeshift(){
wget "https://.../...deb" && [ -f "...deb" ] && { dpkg -i ....deb || apt -f install; }
}
$ touch file && [ -f file ] && { test -d whatever || echo 'apt -f install called'; }
apt -f install called
$ rm file
$ touch file1 && [ -f file ] && { test -d whatever || echo 'apt -f install called'; }
$ touch file1 && [ -f file ] && { test -d whatever || echo 'apt -f install called'; } || echo 'no file downloaded'
no file downloaded
$
#!/bin/bash
FILE="test.txt"
SIZE=$(stat -c %s $FILE)
{ while [ $(stat -c %s $FILE) -lt $SIZE ]
do
cat /dev/urandom | tr -dc 'A-Za-z0-9' | head -c 76
done } | head -c $SIZE > $FILE
#!/bin/bash
declare -A LANGUAGES
BASE="./langs"
for path in $(find $BASE -name '*.lng')
do
base=$(basename $path)
language=${base%.*}
line=$(grep "language" $path)
name=${line#*=}
LANGUAGES[$name]=$language
done
echo ${!LANGUAGES[@]}
echo ${LANGUAGES[@]}
select l in ${!LANGUAGES[@]}
do
echo "Selected: $l"
echo "Selected file: " $BASE/${LANGUAGES[$l]}.lng
break
done
#!/bin/bash
find . -name "*-git*.txt" | (
IFS='
'
while read oldname
do
newname=${oldname//-git}
mv "$oldname" "$newname"
done
)
#!/bin/bash
IFS='
'
exec 3<>data.txt
while read -u 3 line
do
(
IFS=' '
result=()
for word in $line
do
[[ ! "${result[*]}" =~ "$word" ]] && result=(${result[*]} $word)
done
echo ${result[*]}
)
done
#!/bin/bash
res=0
read h1 m1 h2 m2
while :
do
if [ $m1 -eq 0 ]; then
if [ $h1 -gt 12 ]; then
dif=$(($h1-12))
else
[ $h1 -eq 0 ] && dif=12 || dif=$h1
fi
res=$(($res+$dif))
else
[ $m1 -eq 30 ] && ((res++))
fi
[ $h1 -eq $h2 ] && [ $m1 -eq $m2 ] && break
((m1++))
[ $m1 -eq 60 ] && m1=0 && ((h1++))
done
echo $res