Linux
Toggle Swap
by dervish on May.02, 2015, under Linux
#!/bin/bash
free_data="$(free)"
mem_data="$(echo "$free_data" | grep 'Mem:')"
free_mem="$(echo "$mem_data" | awk '{print $4}')"
buffers="$(echo "$mem_data" | awk '{print $6}')"
cache="$(echo "$mem_data" | awk '{print $7}')"
total_free=$((free_mem + buffers + cache))
used_swap="$(echo "$free_data" | grep 'Swap:' | awk '{print $3}')"
echo -e "Free memory:\t$total_free kB ($((total_free / 1024)) MB)\nUsed swap:\t$used_swap kB ($((used_swap / 1024)) MB)"
if [[ $used_swap -eq 0 ]]; then
echo "Congratulations! No swap is in use."
elif [[ $used_swap -lt $total_free ]]; then
echo "Freeing swap..."
sudo swapoff -a
sudo swapon -a
else
echo "Not enough free memory. Exiting."
exit 1
fi
Scott Severance from askubuntu.com
Ubuntu Missing Swap
by dervish on Dec.13, 2014, under Linux, Ubuntu
Fix missing swap on Ubuntu derivatives when using encrypted home directories:
$ swapon -s
Filename Type Size Used Priority
$ free
total used free shared buffers cached
Mem: 1010504 905892 104612 16964 14460 370292
-/+ buffers/cache: 521140 489364
Swap: 0 0 0
$ sudo -s
# fdisk -l | grep swap
..
Disk /dev/mapper/mint--vg-swap_1: 1069 MB, 1069547520 bytes
..
# mkswap /dev/mapper/mint--vg-swap_1 # copy UUID shown into next cmdline
mkswap: /dev/mapper/mint--vg-swap_1: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 1044476 KiB
no label, UUID=08109738-64e7-4504-8bfd-2dff2011551d
# echo "RESUME=UUID=143c43d8-0a77-4d62-a7ae-f53a8e0229a9" > /etc/initramfs-tools/conf.d/resume
# echo "cryptswap1 /dev/sdb3 /dev/urandom swap,cipher=aes-cbc-essiv:sha256" > /etc/crypttab
# update-initramfs -u
update-initramfs: Generating /boot/initrd.img-3.13.0-24-generic
Warning: No support for locale: en_US.utf8
# swapon -s
Filename Type Size Used Priority
/dev/mapper/mint--vg-swap_1 partition 1044476 316 -1
# free
total used free shared buffers cached
Mem: 1010504 863964 146540 16984 12820 326476
-/+ buffers/cache: 524668 485836
Swap: 1044476 316 1044160
Script: jbcleanup.sh
by dervish on Oct.24, 2014, under Linux, Scripts
#!/bin/sh
# 20141024 - Jamey Hopkins
echo "Before: `ls *log* | wc -l` Files at `du -h . | cut -f1`"
[ 0 -ne `find *server.log -mtime +9 | wc -l` ] && find *server.log -mtime +9 | xargs gzip -v
[ 0 -ne `find *server.log.gz -mtime +30 | wc -l` ] && find *server.log.gz -mtime +30 | xargs rm
echo "After : `ls *log* | wc -l` Files at `du -h . | cut -f1`"
20140821 – Scan SCSI Bus for New Disk
by dervish on Aug.21, 2014, under Linux
# 20140821 scan scsi bus for new disks (RHEL 5) – Jamey Hopkins
# echo 1 > /sys/block/sd?/device/rescan (RHEL 6)
cd /sys/class/scsi_host/
for h in `ls`; do echo $h;[ -f $h/scan ] && echo ‘- – -‘ >$h/scan;done
# use partprobe to throw error for unrecognized disk
partprobe
vsftpd respawning too fast, stopped
by dervish on Apr.03, 2014, under Linux
# service vsftpd start
vsftpd start/pre-start, process 19503
# ftp localhost
ftp: connect: Connection refused
ftp>
# tail syslog
Apr 3 19:09:13 posix1c kernel: [5432924.750678] init: vsftpd main process (19514) terminated with status 1
Apr 3 19:09:13 posix1c kernel: [5432924.750692] init: vsftpd main process ended, respawning
Apr 3 19:09:13 posix1c kernel: [5432924.753473] init: vsftpd main process (19517) terminated with status 1
Apr 3 19:09:13 posix1c kernel: [5432924.753489] init: vsftpd main process ended, respawning
Apr 3 19:09:13 posix1c kernel: [5432924.756226] init: vsftpd main process (19520) terminated with status 1
Apr 3 19:09:13 posix1c kernel: [5432924.756240] init: vsftpd main process ended, respawning
Apr 3 19:09:13 posix1c kernel: [5432924.758928] init: vsftpd main process (19523) terminated with status 1
Apr 3 19:09:13 posix1c kernel: [5432924.758942] init: vsftpd main process ended, respawning
Apr 3 19:09:13 posix1c kernel: [5432924.761728] init: vsftpd main process (19526) terminated with status 1
Apr 3 19:09:13 posix1c kernel: [5432924.761743] init: vsftpd respawning too fast, stopped
# vsftpd
500 OOPS: unrecognised variable in config file: allow_writeable_chroot
# grep allow_writeable_chroot /etc/vsftpd.conf
allow_writeable_chroot=YES
Comment out:
# grep allow_writeable_chroot /etc/vsftpd.conf
#allow_writeable_chroot=YES
# service vsftpd start
vsftpd start/running, process 19652
Service stays up:
# ftp localhost
Connected to localhost.
220 (vsFTPd 2.3.5)
Name (localhost:user):