Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

Saturday, August 5, 2017

Add speech to your Fedora system

This article first appeared on Fedora Magazine

By default, Fedora Workstation ships a small package called espeak. It adds a speech synthesizer — that is, text-to-speech software.
In today’s world, talking devices are nothing impressive as they’re very common. You can find speech synthesizers even in your smartphone, a product like Amazon Alexa, or in the announcements at the train station. In addition, synthesized voices are nowadays more or less similar to human speech. We live in a 1980s science fiction movie!
The voice produced by espeak may sound a bit primitive compared to the aforementioned tools. But at the end of the day espeak produces good quality speech. And whether you find it useful or not, at least it can provide some amusement.

Running espeak

In espeak you can set various parameters using command line options. Examples include:
  • amplitude (-a)
  • pitch adjustment (-p)
  • speed of sentences (-s)
  • gap between words (-g)
Each of these options produces various effects and may help you achieve a cleaner voice.
You can also select different voice variants with command line options. For example, try -ven+m3 for a different English male voice, and -ven+f1 for a female one. You can also use different languages. For a list, run this command:
espeak --voices
Note that many languages other than English are experimental attempts.
To create a WAV file instead of actually speaking something, use the -w option:
espeak -w out.wav "Audio file test"
The espeak utility also reads the content of a file for you.
espeak -f plaintextfile
Or you can pass the text to speech from the standard input. In this way, as a simple example, you can build a talking box that alerts you to an event using a voice. Your backup is completed? Add this command to the end of your script:
echo "Backup completed" | espeak -s 160 -a 100 -g 4
Suppose an error shows up in a log file:
tail -1F /your/log/file | grep --line-buffered 'ERROR' | espeak
Or perhaps you want a speaking clock telling you every minute what time it is:
while true; do date +%S | grep '00' && date +%H:%M | espeak; sleep 1; done
As you can guess, use cases are limited only by your imagination. Enjoy your new talking Fedora system!

Monday, December 12, 2016

Percona Monitoring Plugins for Nagios on SmartOS

Using Percona monitoring plugins inside a SmartOS branded zone, I get an error related to the local command.

percona-monitoring-plugins-1.1.7/nagios/bin/pmp-check-mysql-innodb[58]: local: not found [No such file or directory]

To solve this problem, perform the following command against every script (i.e. inside the nagios/bin/ directory).

sed -i 's/^\( \{2,4\}\)local /\1typeset /' *

Tuesday, June 30, 2015

Nagios plugin: check oracle query

Here is a Nagios plugin useful to connect to an Oracle database, perform a query and check the result by a regular expression.

Please note: it works for me, but it is far from perfect.

https://github.com/alcir/nagios/tree/master/check_oracle_query

Examples

./check_oracle_query.sh -H 192.168.1.10 -u user -w pass -p 1521 -s SID -n ID -q "select * from table" -e "^[1-9].* rows selected"

./check_oracle_query.sh -H 10.0.0.47 -u user -w pass -p 1521 -s SID01 -n ID1 -q "select * from dual" -e "^X"

Thursday, March 5, 2015

Installing check_mk agent on a SmartOS global zone

The check_mk agent uses inetd (or xinetd).
On Solaris, and on SmartOS, inetd is a legacy facility.
In addition, on the SmartOS GZ, the stuff configured in the /etc directory doesn't survive to reboots, as you may know.

So, since I already use a method to set the hostname at boot time, as described in this blog https://nickebo.net/creating-a-custom-motd-in-the-smartos-global-zone/, I added a pair of lines in the postboot script.


echo "check_mk        6556/tcp" >> /etc/services
echo "check_mk stream tcp nowait root /usr/sbin/tcpd /opt/custom/bin/check_mk_agent" >> /etc/inet/inetd.conf
inetconv
inetconv -e



Then download the check_mk solaris agent from github and put it in the /opt/custom/bin/ directory.


Obviously, if you don't want to reboot the GZ, but enable the service right now, issue the same commands as above.

Remember to change the MK_LIBDIR and the MK_CONFDIR variables in the /opt/custom/bin/check_mk_agent script in order to use additional plugins or configurations.


Friday, September 19, 2014

SmartOS: move (migrate) a VM to another Global Zone

To move a running virtual machine, either a zone or a KVM, from an hypervisor (Global Zone) to another, I usually follow these steps in an handicraft way.

In order to minimize downtime, there are 2 steps.
The first snapshot and transfer of the ZFS filesystem will be done without halting the VM.
In the second step we will shutdown the VM, take another snapshot, then we will send it using an incremental transfer, that is very fast.

First of all you need the UUID of the VM you want to move from a global zone to another GZ.

[root@gz1 /]#vmadm list
UUID                                  TYPE  RAM      STATE             ALIAS
561b686e-3119-4ab0-932e-20fc944fb001  KVM   512      running           vm1
e44f3c76-4acb-11e3-a536-a7cfa8b66838  OS    512      running           vm2
b803b5b9-bc86-4d0f-b450-16862e7bd7ed  OS    2048     running           vm3



Now we need the list of all the ZFS filesystem related to that VM.

[root@gz1 ~]# zfs list -o name | grep 561b686e-3119-4ab0-932e-20fc944fb001

zones/561b686e-3119-4ab0-932e-20fc944fb001
zones/561b686e-3119-4ab0-932e-20fc944fb001-disk0
zones/561b686e-3119-4ab0-932e-20fc944fb001-disk1
zones/cores/561b686e-3119-4ab0-932e-20fc944fb001


Now we must create a snapshot of every ZFS.
Note: at this time the VM doesn't need to be stopped, you can leave it up and running, just to minimize downtime.

[root@gz1 ~]# zfs snapshot zones/561b686e-3119-4ab0-932e-20fc944fb001@tosend
[root@gz1 ~]# zfs snapshot zones/561b686e-3119-4ab0-932e-20fc944fb001-disk0@tosend
[root@gz1 ~]# zfs snapshot zones/561b686e-3119-4ab0-932e-20fc944fb001-disk1@tosend
[root@gz1 ~]# zfs snapshot zones/cores/561b686e-3119-4ab0-932e-20fc944fb001@tosend


Now it is time to send these snapshots to the destination. It may require a lot of time.

[root@gz1 ~]# zfs send zones/561b686e-3119-4ab0-932e-20fc944fb001@tosend | ssh gz2.domain zfs receive -v zones/561b686e-3119-4ab0-932e-20fc944fb001[root@gz1 ~]# zfs send zones/561b686e-3119-4ab0-932e-20fc944fb001-disk0@tosend | ssh gz2.domain zfs receive -v zones/561b686e-3119-4ab0-932e-20fc944fb001-disk0[root@gz1 ~]# zfs send zones/561b686e-3119-4ab0-932e-20fc944fb001-disk1@tosend | ssh gz2.domain zfs receive -v zones/561b686e-3119-4ab0-932e-20fc944fb001-disk1
[root@gz1 ~]#
zfs send zones/cores/561b686e-3119-4ab0-932e-20fc944fb001@tosend | ssh
gz2.domain zfs receive -v zones/cores/561b686e-3119-4ab0-932e-20fc944fb001

After that, we have to stop the virtual machine.

[root@gz1 ~]# vmadm stop 561b686e-3119-4ab0-932e-20fc944fb001

And get additional snapshots of the ZFS filesystems, like before, giving them a different name. Now, these snapshots are potentially in a consistent state, since the operating system inside the virtual machine is not running.

[root@gz1 ~]# zfs snapshot zones/cores/561b686e-3119-4ab0-932e-20fc944fb001@tosend-last 
[root@gz1 ~]# zfs snapshot zones/561b686e-3119-4ab0-932e-20fc944fb001-disk1@tosend-last 
[root@gz1 ~]# zfs snapshot zones/561b686e-3119-4ab0-932e-20fc944fb001-disk0@tosend-last 
[root@gz1 ~]# zfs snapshot zones/561b686e-3119-4ab0-932e-20fc944fb001@tosend-last


Finally, we have to send these ZFS snapshots using incremental send. It will take a little bit of time.

[root@gz1 ~]# zfs send -i zones/561b686e-3119-4ab0-932e-20fc944fb001@tosend zones/561b686e-3119-4ab0-932e-20fc944fb001@tosend-last | ssh gz2.domain zfs receive -Fv zones/561b686e-3119-4ab0-932e-20fc944fb001
[root@gz1 ~]#
zfs send -i zones/561b686e-3119-4ab0-932e-20fc944fb001-disk0@tosend zones/561b686e-3119-4ab0-932e-20fc944fb001-disk0@tosend-last | ssh
gz2.domain zfs receive -Fv zones/561b686e-3119-4ab0-932e-20fc944fb001-disk0
[root@gz1 ~]#
zfs send -i zones/561b686e-3119-4ab0-932e-20fc944fb001-disk1@tosend zones/561b686e-3119-4ab0-932e-20fc944fb001-disk1@tosend-last | ssh
gz2.domain zfs receive -Fv zones/561b686e-3119-4ab0-932e-20fc944fb001-disk1

[root@gz1 ~]# zfs send -i zones/cores/561b686e-3119-4ab0-932e-20fc944fb001@tosend zones/cores/561b686e-3119-4ab0-932e-20fc944fb001@tosend-last | ssh gz2.domain zfs receive -v zones/cores/561b686e-3119-4ab0-932e-20fc944fb001

Some last operations.
Grab the line related to the VM from inside the /etc/zones/index in the source global zone, and paste it at the end of same file in the destination global zone.

[root@gz1 ~]# cat /etc/zones/index | grep 561b686e-3119-4ab0-932e-20fc944fb001


[root@gz2 ~]# echo "561b686e-3119-4ab0-932e-20fc944fb001:installed:/zones/561b686e-3119-4ab0-932e-20fc944fb001:561b686e-3119-4ab0-932e-20fc944fb001" >> /etc/zones/index

Finally, copy the xml configuration file from the source global zone, to the destination one.


[root@gz1 ~]#scp /etc/zones/561b686e-3119-4ab0-932e-20fc944fb001.xml gz2.domain:/etc/zones/561b686e-3119-4ab0-932e-20fc944fb001.xml 

At this point, you can boot the VM on the destination global zone, check if all is working as expected, then delete the old VM from the source global zone.

Wednesday, August 7, 2013

using send_nsca from SmartOS global zone

If you don't want to install pkgin in the global zone, but you want to use Nagios send_nsca command, this is how I did it.

Inside a zone install the nagios-nsca package.

pkgin in nagios-nsca-2.9.1nb2


From the global zone, cd to the zone zfs and copy these files in a place of your own.

cd /zones/<uuid>

cp opt/local/gcc47/x86_64-sun-solaris2.11/lib/amd64/libgcc_s.so.1 /opt/custom/nsca/

cp opt/local/gcc47/x86_64-sun-solaris2.11/lib/amd64/libgcc_s.so.1
/opt/custom/nsca/

cp opt/local/lib/libmcrypt.so.4
/opt/custom/nsca/


Create a configuration file

vi /opt/custom/nsca/send_nsca.cfg


Now set the LD_LIBRARY_PATH variable and run the command

export LD_LIBRARY_PATH=/opt/custom/nsca; echo "host;passive_check;0;All seems to be OK" | /opt/custom/nsca/send_nsca -H nagios.ip -p 5667 -d ";" -c /opt/custom/nsca/send_nsca.cfg

nagios plugin to compare (master/slave) SOA records

This is a Nagios script to compare the master ns and the slave ns SOA records.
So you can know if the slave zone is expired, or is not in sync with the master.

http://exchange.nagios.org/directory/Plugins/Network-Protocols/DNS/checkexpire/details

https://github.com/alcir/checkexpire.sh


Tuesday, August 6, 2013

mass destroy zfs snapshots

Please pay attention...

zfs list -t snapshot|awk '{print $1}' > /tmp/zfstodestroy

Edit the file to delete the snapshots you don't want to delete!
Then:

while read uuid; do zfs destroy $uuid; done < <(cat /tmp/zfstodestroy)

Wednesday, July 31, 2013

bash while loop, function and ssh

Yesterday I struggled an entire morning with a while loop inside a bash script.
The loop ended even if there was a lot of work to do.
And the while loop ended only when I was calling a function inside another function.

The function contained an ssh call to a remote host to get a result.
Such ssh connection, opening a shell on the remote host, maybe killed my while environment?

The solution:

remote() {
  echo -e "Checking if it is the first time we zfs send to remote $1"
 
  ssh $sshparam zfs list $1 </dev/null &>/dev/null 
 
  EL=$?
  if [ $EL -eq 0 ]
  then
    return 1
  else
    return 0
  fi
} 

</dev/null &>/dev/null 

Tuesday, January 29, 2013

batch convert dv to avi xvid using ffmpeg

I am using Openindiana.

find bk/Video -type f -exec ~/mmpeg.sh {} \;

The mmpeg.sh script is based on sandipb script.
(Some variables may be unuseful).

https://github.com/alcir/mystuff/blob/master/mmpeg.sh

The converted files will go in /media/003-9VT166/converted/ directory using as name the full path starting from where find was launched.

So, the file
./bk/Video/2012_12/video01.dv
will become
/media/003-9VT166/converted/bk_Video_2012_12_video01.avi 

Please note: I had no time to handle spaces in file names.

Friday, October 19, 2012

centos kvm console

To enable console access from the host command line to a CentOS guest, this was an useful link

Monday, August 13, 2012

Cycling date in bash

Maybe you want to cycle a time frame from a day to another, taking in consideration how many days a month have (also for leap years). Here is how you can do in bash.

Date format is: YYYYMMDD

#!/bin/bash

b=$1
e=$2

while [ "$b" -le "$e" ]
do
&nbsp;&nbsp;&nbsp;echo $b
&nbsp;&nbsp;&nbsp;b=$(date +%Y%m%d -d "$b +1 day")
done




Execute it

./loopdate.sh 20090101 20090301


Result

20090101
20090102
...
20090226
20090227
20090228
20090301


It works on Linux, and using gdate (from opencsw, blastwave) on Solaris. On Mac OS X it doesn't work.

Wednesday, July 25, 2012

Dcm4chee: move study to trash using command line

Using twiddle.sh on command line:

/export/dcm4chee-2.17.2-mysql/bin/twiddle.sh -s 127.0.0.1 -u admin -p password invoke dcm4chee.archive:service=ContentEditService moveStudyToTrash 1.2.826.0.1.3680043.8.291.20091126113000.28044

Where 1.2.826.0.... is the Study Instance UID

This can be useful for mass trashing or if you have timeout problem on large studies.

Friday, July 20, 2012

Nagios plugin: check_SL500

check_SL500 is a shell script to check various things on a Sun StorageTek(TM) SL500 Modular Library System (maybe it works with other models). Currently the script can check:
  • fan status
  • drives temperature
  • robot status
  • cap status
  • controller status
  • overall (toplevel) status
  • system load