Thursday, 17 August 2017

How to delete files with strange characters

If you have files that you can not delete due to strange characters, find the inode and delete them via that.
root@server puppetlabs # ls
activemq      code          enterprise                        installer    license.key.2016  orchestration-services  puppetserver  r10k
client-tools  code-staging  --exclude-dirs=code,code-staging  license.key  mcollective       puppet                  pxp-agent
[2017-08-17 16:03:42]
root@server puppetlabs # rm --exclude-dirs\=code\,code-staging
rm: unrecognized option '--exclude-dirs=code,code-staging'
Try 'rm ./'--exclude-dirs=code,code-staging'' to remove the file ‘--exclude-dirs=code,code-staging’.
Try 'rm --help' for more information.
[2017-08-17 16:02:30]
No chance with the above, so use:
root@server puppetlabs # ls -i
918314 activemq      918427 code-staging                      917739 installer         918184 mcollective             918048 puppetserver
918293 client-tools  918390 enterprise                        945600 license.key       918298 orchestration-services  918212 pxp-agent
918146 code          927457 --exclude-dirs=code,code-staging  934089 license.key.2016  918195 puppet                  918294 r10k
[2017-08-17 16:04:36]
root@server puppetlabs # find . -inum 927457 -delete
[2017-08-17 16:04:59]
root@picard puppetlabs # ls
activemq      code          enterprise  license.key       mcollective             puppet        pxp-agent
client-tools  code-staging  installer   license.key.2016  orchestration-services  puppetserver  r10k
[2017-08-17 16:04:59]

Friday, 4 August 2017

iSCSI on Oracle Linux

Install the iSCSI utils:
# yum install iscsi-initiator-utils
Check out the initiator file to get the IQN:
# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.1988-12.com.oracle:acbd8bf16757

Monday, 31 July 2017

Can not write to web app directory - selinux issue

Is the content directory of some web app living somewhere that selinux is enforcing it policy? Perform the following to make directory writeable:

root@icinga2-p0 etc # semanage fcontext -a -t httpd_sys_rw_content_t "/etc/icingaweb2(/.*)?"


root@icinga2 etc # restorecon -Rv /etc/icingaweb2
restorecon reset /etc/icingaweb2 context system_u:object_r:etc_t:s0->system_u:object_r:httpd_sys_rw_content_t:s0
restorecon reset /etc/icingaweb2/setup.token context unconfined_u:object_r:etc_t:s0->unconfined_u:object_r:httpd_sys_rw_content_t:s0
restorecon reset /etc/icingaweb2/modules context system_u:object_r:etc_t:s0->system_u:object_r:httpd_sys_rw_content_t:s0
restorecon reset /etc/icingaweb2/modules/translation context system_u:object_r:etc_t:s0->system_u:object_r:httpd_sys_rw_content_t:s0
restorecon reset /etc/icingaweb2/modules/translation/config.ini context system_u:object_r:etc_t:s0->system_u:object_r:httpd_sys_rw_content_t:s0
restorecon reset /etc/icingaweb2/modules/setup context system_u:object_r:etc_t:s0->system_u:object_r:httpd_sys_rw_content_t:s0
restorecon reset /etc/icingaweb2/modules/setup/config.ini context system_u:object_r:etc_t:s0->system_u:object_r:httpd_sys_rw_content_t:s0

Monday, 17 July 2017

Update, compare kernel versions - reboot within 6hours period - CentOS

#!/bin/sh
host=`hostname -f`
date=`date`

# run updates to get latest software and kernel
yum -y update
maxdelay=$((6*60))
rdelay=$(($RANDOM%maxdelay))
sdelay=$(($rdelay*60))
kernel=`uname -r`
latest=`rpm -q kernel --queryformat '%{installtime} %{version}-%{release}.%{arch}\n' | sort -n -k1 | tail -1 | cut -d ' ' -f 2`
sdate=`date`

if [ "$kernel" = "$latest" ];
then
        echo "No need to reboot..."
        echo "You are running the latest kernel: $kernel"
else
        echo "There is a new kernel. You need a reboot..."
        echo "Current kernel: $kernel"
        echo "The latest kernel: $latest"
        echo "$sdate\nCurrent kernel: $kernel\nLatest kernel: $latest"
        echo "Sleeping for $sdelay seconds..."
        sleep $sdelay
        echo "Waking up and rebooting..."
        /sbin/reboot
fi

Monday, 19 June 2017

Install GRUB loader when Debian fails to boot

mount /dev/sdXY /mnt

mount --bind /dev /mnt/dev &&
mount --bind /dev/pts /mnt/dev/pts &&
mount --bind /proc /mnt/proc &&
mount --bind /sys /mnt/sys

chroot /mnt

grub-install /dev/sdX
grub-install --recheck /dev/sdX

Wednesday, 14 June 2017

Disable service start up at re/boot - Debian 6

The following is the chkconfig equivalents on Debian 6:
update-rc.d  <service> defaults
update-rc.d  <service> start 20 3 4 5
update-rc.d -f <service>  remove
Part of the man page:
UPDATE-RC.D(8)                                   sysv-rc                                   UPDATE-RC.D(8)

NAME
       update-rc.d - install and remove System-V style init script links

SYNOPSIS
       update-rc.d [-n] [-f] name remove

       update-rc.d [-n] name defaults [NN | SS KK]

       update-rc.d  [-n]  name  start|stop  NN  runlevel  [runlevel]...   .  start|stop NN runlevel [run‐
              level]...  . ...

       update-rc.d [-n] name disable|enable [ S|2|3|4|5 ]

DESCRIPTION
       update-rc.d updates the System V style init script links /etc/rcrunlevel.d/NNname whose target  is
       the script /etc/init.d/name.  These links are run by init when it changes runlevels; they are gen‐
       erally used to start and stop system services such as daemons.  runlevel is one of  the  runlevels
       supported  by  init,  namely, 0123456789S, and NN is the two-digit sequence number that determines
       where in the sequence init will run the scripts.

       This manpage documents only the usage and behaviour of update-rc.d.  For a discussion of the  Sys‐
       tem V style init script arrangements please see init(8) and the Debian Policy Manual.

Friday, 19 May 2017

CentOS 5 EOL - Yum repo issue

Now that CentOS 5 has gone end of life, there's no update repos left to use:
-bash-3.2# cat /etc/redhat-release
CentOS release 5.11 (Final)
-bash-3.2# yum update
Loaded plugins: downloadonly, fastestmirror
Determining fastest mirrors
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
 Eg. Invalid release/
removing mirrorlist with no valid mirrors: /var/cache/yum/base/mirrorlist.txt
Error: Cannot find a valid baseurl for repo: base
All repo contents have been moved to http://vault.centos.org so to fix the problem, the other repos must be removed:
-bash-3.2# ls /etc/yum.repos.d/CentOS-
CentOS-Base.repo       CentOS-Media.repo      CentOS-Vault.repo
CentOS-Debuginfo.repo  CentOS-Sources.repo    CentOS-fasttrack.repo
-bash-3.2# ls /etc/yum.repos.d/CentOS-
Leaving only CentOS-Vault.repo:
-bash-3.2# yum update
Loaded plugins: downloadonly, fastestmirror
Determining fastest mirrors
Setting up Update Process
No Packages marked for Update
-bash-3.2#