Category: Linux
-
Bash while loop input (stdin reading from while-input) fix
while read line <&3; do echo “==== $line ====”; yes y | sqlmap -u http://$line/ –crawl=1; read -p press\ enter; done 3< webservers.ip Using input 3 to read your list, leaving stdin untouched.
-
Rpmfusion fedora and h264/codecs
yum install https://download1.rpmfusion.org/{free/fedora/rpmfusion-free,nonfree/fedora/rpmfusion-nonfree}-release-$(rpm -E %fedora).noarch.rpm yum install install compat-ffmpeg28 ffmpeg-libs
-
Bash array operations and examples
Split to array: while IFS=’;’ read -ra ADDR; do for i in “${ADDR[@]}”; do # process “$i” done done <<< “$IN” Define: distro=(“redhat” “debian” “gentoo”) Element: ${ArrayName[subscript]} Length: echo “${#distro[@]}” Example !/bin/bash define array name server names FQDN NAMESERVERS=(“ns1.nixcraft.net.” “ns2.nixcraft.net.” “ns3.nixcraft.net.”) get length of an array tLen=${#NAMESERVERS[@]} use for loop read all nameservers for ((…
-
Bash color variables
# Reset Color_Off=’\033[0m’ # Text Reset # Regular Colors Black=’\033[0;30m’ # Black Red=’\033[0;31m’ # Red Green=’\033[0;32m’ # Green Yellow=’\033[0;33m’ # Yellow Blue=’\033[0;34m’ # Blue Purple=’\033[0;35m’ # Purple Cyan=’\033[0;36m’ # Cyan White=’\033[0;37m’ # White # Bold BBlack=’\033[1;30m’ # Black BRed=’\033[1;31m’ # Red BGreen=’\033[1;32m’ # Green BYellow=’\033[1;33m’ # Yellow BBlue=’\033[1;34m’ # Blue BPurple=’\033[1;35m’ # Purple BCyan=’\033[1;36m’ #…
-
Certbot centos 7
pip uninstall requests yum reinstall python-requests pip uninstall six yum reinstall python-six pip uninstall urllib3 yum reinstall python-urllib3 ; yum install http://cbs.centos.org/kojifiles/packages/pyOpenSSL/16.2.0/3.el7/noarch/python2-pyOpenSSL-16.2.0-3.el7.noarch.rpm ; yum install certbot certbot-apache
-
Tail: prepend file name to tailing output (bash)
cd /opt/arcsight/connectors/; tail -f *_con1_rsyslog_paloalto_2500*/current/logs/agent.out.wrapper.log | awk ‘/^==> / {a=substr($0, 5, length-8); next} {print a”:”$0}’
-
Personal (manual) template for internal hosts
This might help someone else, too. These are the things I do for an internal VM (on my hypervisor at home). This document will/might evolve over time. Default OS is centos7. yum -y install epel-release && yum -y update && yum -y install wget vim htop tcpdump yum-cron yum-utils ntp figlet lynis bind-utils bash-completion mlocate…
-
Bash suppress all output of script (echo off – style)
exec 1>/dev/null 2>/dev/null at the top of your script
-
Install Domoticz on Centos 7
Old version below NEW ADDED NOTES (Thanks Charles Orbello) The new version of domoticz requires a new version of cmake and the old version of domotics need a different version of open-zwave flow work with the following release (and I added libusb-devel for my zigate ): wget https://github.com/domoticz/domoticz/archive/3.8153.tar.gz wget https://github.com/OpenZWave/open-zwave/archive/V1.5.tar.gz We are…
-
Yum Error: database disk image is malformed fix
root@host:~# yum update Loaded plugins: product-id, search-disabled-repos, security, subscription-manager Setting up Update Process Error: database disk image is malformed root@host:~# yum clean all Loaded plugins: product-id, search-disabled-repos, security, subscription-manager Cleaning repos: * Cleaning up Everything root@host:~# mv /var/lib/rpm/__db* /tmp root@host:~# rpm –rebuilddb
-
Bash compound commands (()){{}}{}[[]]
Compound Commands A compound command is one of the following. In most cases a list in a command’s description may be separated from the rest of the command by one or more newlines, and may be followed by a newline in place of a semicolon. (list) list is executed in a subshell environment (see COMMAND…
-
RHEL/Fedora auto apply updates (dnf/yum)
[root@zotac3 ~]# dnf -y install dnf-automatic Last metadata expiration check: 2:07:13 ago on Tue Sep 27 06:13:59 2016. Dependencies resolved. =============================================================================================================================================================================================================================================================================================================================== Package Arch Version Repository Size =============================================================================================================================================================================================================================================================================================================================== Installing: dnf-automatic noarch 1.1.10-1.fc24 updates 90 k Transaction Summary =============================================================================================================================================================================================================================================================================================================================== Install 1 Package Total download size: 90 k Installed size: 35 k Downloading Packages: dnf-automatic-1.1.10-1.fc24.noarch.rpm 18 kB/s |…
-
Run programs without execute rights on file
/bin/bash script.sh /lib64/ld-linux-x86-64.so.2 binary.bin /usr/bin/php file.php
-
Fix broken yum database (DB_RUNRECOVERY)
error: rpmdb: BDB0113 Thread/process 633/140720390891328 failed: BDB1507 Thread died in Berkeley DB library error: db5 error(-30973) from dbenv->failchk: BDB0087 DB_RUNRECOVERY: Fatal error, run database recovery error: cannot open Packages index using db5 – (-30973) error: cannot open Packages database in /var/lib/rpm CRITICAL:yum.main: Error: rpmdb open failed [root@crowdfundmailer ~]# rm -f /var/lib/rpm/__db* [root@crowdfundmailer ~]# rpm –rebuilddb…
-
Bash keyboard shortcuts
Found here: http://ss64.com/bash/syntax-keyboard.html Bash Keyboard Shortcuts Moving the cursor: Ctrl + a Go to the beginning of the line (Home) Ctrl + e Go to the End of the line (End) Ctrl + p Previous command (Up arrow) Ctrl + n Next command (Down arrow) Alt + b Back (left) one word Alt + f…
-
Reset HP/HPE iLO 4 password with CLI on Linux
File: Install hponcfg-4.6.0-0.x86_64.rpm , get it here: http://h20564.www2.hpe.com/hpsc/swd/public/detail?swItemId=MTX_5ab6295f49964f16a699064f29 . Not available anymore? I made a base64 version of the thing here: http://pastebin.com/raw/XQyXBdCg . Run hponcfg -f pass.xml .
-
Self extracting zipped encrypted linux package
#!/bin/bash T=`mktemp -d /tmp/$$XXXX`;trap “rm -rf $T” EXIT SIGINT; tail -n+3 $0|openssl enc -d -aes-256-cbc|tar zx -C $T;C=`pwd`; cd $T;./_;cd $C;exit 0 build: #!/bin/bash find . -name “*~” -delete TMP=`mktemp -d /tmp/$$.XXXXX` trap “rm -rf $TMP” EXIT # Create payload tar -czf $TMP/payload –exclude=*~ ./* cd .. #?? DST=./packages/`date +%Y%m%d`/sysprep.run mkdir `dirname $DST` ( tail…
-
Fix rpm/yum database (BDB0087 DB_RUNRECOVERY: Fatal error, run database recovery)
$ sudo yum update error: rpmdb: BDB0113 Thread/process 11565/140378074454016 failed: BDB1507 Thread died in Berkeley DB library error: db5 error(-30973) from dbenv->failchk: BDB0087 DB_RUNRECOVERY: Fatal error, run database recovery error: cannot open Packages index using db5 – (-30973) error: cannot open Packages database in /var/lib/rpm CRITICAL:yum.main: Error: rpmdb open failed Fix by doing: rpm –rebuilddb
-
RHEL replace rsyslog with rsyslog7 without clearing dependencies
You want to install rsyslog7 but you get: Error: rsyslog7 conflicts with rsyslog-5.8.10-10.el6_6.x86_64 So you choose to erase/remove rsyslog first, but this removes: cronie, cronie-anacron, crontabs, redhat-lsb, redhat-lsb-compat, redhat-lsb-core, redhat-lsb-graphics, redhat-lsb-printing, rsyslog-relp, sysstat The solution is to use yum shell (EDIT: OR USE YUM SWAP) # yum shell Loaded plugins: security Setting up Yum Shell…
-
Nagios, nrpe and selinux policies (audit)
Selinux seems to “dontaudit” logs by default. This means that when selinux is permissive, your plugins will work, and when you setenforce 1 your server, plugins fail. This all happens without warnings. If you see this happening: Disable dontaudit: semodule -DB See avc entries filling up audit.log, pipe through audit2allow. Enable again: semodule -B
-
Bash percentage calculate snippet
MEMLINE=$( tac $MGRBASE/$REL_LOGLOC/server.status.log | egrep -m1 ‘\*\*.*Memory Status:’ ) USED=$( echo “$MEMLINE” | egrep -o ‘[0-9\.,]+ MB Used’ | sed ‘s/\..*//;s/,//’ ) MAX=$( echo “$MEMLINE” | egrep -o ‘[0-9\.,]+ MB Max’ | sed ‘s/\..*//;s/,//’ ) PERC=$( printf “%.0f” $(echo “scale=2;($USED/$MAX)*100″ | bc) ) if [[ $PERC -gt $MEM_CRIT_PERC ]]; then ERRORS=”$ERRORS memory ${PERC}%” elif [[…
-
Bash file age check snippet
if [[ -f $BACKUP_LOCKFILE ]]; then #Check age if [[ $(( $( date +%s ) – $(stat -c %Y $BACKUP_LOCKFILE ) )) -gt $BACKUP_MAXLENGTH_SECS ]]; then echo “Backup takes too long” else echo “Doing backup” fi fi
-
Fix requested NFS version or transport protocol is not supported
I got this on RHEL 6: requested NFS version or transport protocol is not supported Restarting the NFS daemon fixed this. Guess some libraries were updated. Haven’t taken the time to investigate further, maybe if the problem shows up more often… ;)
-
Set hostname RHEL7
Setting hostname via /etc/sysconfig/network does not seem to work anymore. Instead use hostnamectl set-hostname hostname.domain.
-
Cron headers unix / linux
Compact: #.—————- min (0-59) #| .————- hr (0-23) #| | .———- dom (1-31) #| | | .——- mon (1-12) #| | | | .—- dow (0-7|mon-sun0) #| | | | | Wide:
-
Delete old yum/rpm packages from repository (reposync)
repomanage -k2 –old /data/repo/data/el-6-epel | xargs rm -f
-
[FIX] The GPG keys listed for the “*” repository are already installed but they are not correct for this package.
I got: Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release The GPG keys listed for the “RHEL6 Server” repository are already installed but they are not correct for this package. Check that the correct key URLs are configured for this repository. Fix: Run the update command with -v. You will get the same output, but before the error, you…
-
[FIX] Clean up old puppet reports and reclaim mysql space (ibdata)
MySQL for puppet dashboard gets BIG. You can make this smaller by deleting old records. Source for this article is here. To get the size in GB of the dashboard: # mysql -uroot -ppassword > SELECT CONCAT ( ROUND( ( ( SUM(DATA_LENGTH)+SUM(INDEX_LENGTH) ) / 1024 / 1024 / 1024 ) ,2 ), ” GB”) as…