Monday 30 April 2012

SunOS/Solaris - Xymon make error (locator symbol referencing errors in xymond_worker.o)


Xymon
Xymon is a piece of software for multiple platforms which allows system administrators to monitor resources and usage. Computer monitoring systems are used to repeatedly gather data from various monitored systems for the purpose of real-time incident notification, system health verification, performance analysis, and longitudinal capacity planning.


Problem
gcc -o ../client/xymond_client -Wl,-R/opt/csw/lib xymond_client.o xymond_worker.o xymond_buffer.o client_config.o ../lib/xymonclient.a -L/opt/csw/lib -lpcre -lresolv -lsocket -lnsl
Undefined first referenced
symbol in file
locator_serverdown xymond_worker.o
locator_serverup xymond_worker.o
locator_init xymond_worker.o
locator_register_server xymond_worker.o
ld: fatal: Symbol referencing errors. No output written to ../client/xymond_client
collect2: ld returned 1 exit status
gmake[1]: *** [../client/xymond_client] Error 1
gmake[1]: Leaving directory `/tmp/xymon/xymond'
gmake: *** [xymond-client] Error 2


I was receiving this error for Xymon versions: 4.2.3 to 4.3.7 when trying to make a client version of Xymon.


To repeat the process, this is exactly what I did...
1. SSH onto a Solaris box (SunOS servername 5.9 Generic_112233-05 sun4u sparc SUNW,Sun-Fire-V210) as root.

2. Unzip Xymon source and run configure for a client install "./configure --client"

3. 'gmake' to make the libraries.


Solution
The error relates to a missing symbol that requires referencing in the Makefile so gcc knows where to find the locator symbols.

Add "locator.o" to CLIENTLIBOBJS in lib/Makefile

Now you should be able to do a make.

Thursday 26 April 2012

Managing Swapfiles in Linux


Swapfiles
If you run anything close to a modern operating system, you almost certainly interact with a swap file. You might be familiar with the basics of how these work: they allow your OS to prioritize more frequently-used pages in main memory and move the less frequently-used ones to disk. But there's a lot going on underneath the covers. Here's a simple guide to swap files in Linux.


Making a new swap file is a simple process. In this example, we'll make a 2 GiB swap file and make it available to the system as additional swap space. We'll use swapfile as the name of the example swap file, but there is nothing special about the name of the file or its extension. You may use anything you wish.

First, we need to create the swap file itself. We'll use a stream of zeroes as the input source (if=/dev/zero), and write it out to a file named swapfile in the root directory. We will write 2048 (count=2048) blocks each 1 MiB in size (bs=1M). Depending on the speed of your hard disks, this may take a little while.


Code Snippet
  1. dd if=/dev/zero of=/swapfile bs=1M count=2048
  2. chmod 600 /swapfile
  3. mkswap /swapfile
  4. swapon -v /swapfile
End of Code Snippet

mkswap - Formats this file and prepares it for use as a swapping space. The mkswap utility sets up a swap area on a device or file.

swapon - After formatting it, the swap can now be added to our system. The swapon utility activates the swap region.



Reboot Persistence
To activate /swapfile after Linux system reboot, add entry to /etc/fstab file. Open this file using a text editor such as vi...
Code Snippet
  1. vi /etc/fstab
End of Code Snippet


Append the following line:
Code Snippet
  1. /swapfile swap swap defaults 0 0
End of Code Snippet

Creating a Live USB with MAC and Windows



Live USB
A live USB is a USB flash drive or a USB external hard disk drive containing a full operating system that can be booted. Live USBs are closely related to live CDs, but sometimes have the ability to persistently save settings and permanently install software packages back onto the USB device.


Example
Here's an example, we would like to take a distribution of ubuntu linux, and install it on to a USB Flash Drive. We can then insert it into a machine, change the BIOS order, and boot directly from the USB and use the OS directly on the flash drive.


MAC OS X

1. [Optional] If your OS image (I.e. ubuntu-11.10-desktop-i386.iso) is an ISO file, we need to convert this into .img format. We can do this by using the hdiutil utility.

Code Snippet
  1. hdiutil convert -format UDRW -o ubuntu-11.10-desktop-i386.img ubuntu-11.10-desktop-i386.iso
End of Code Snippet


2. Enter this command into a Terminal window...
Code Snippet
  1. diskutil list
End of Code Snippet

We need to identify which drive is our USB Flash Drive. If you cannot tell, then run the command before inserting drive, and again, afterwards. You will notice which entry belongs to the newly inserted drive. I.e. /dev/disk3


3. Mac OS X will automatically mount the memory stick into Finder, so we must unmount the drive (This is not the same as ejecting it) and it will prevent us from seeing "Resource Busy" errors.
Code Snippet
  1. sudo diskutil umountDisk /dev/diskX
End of Code Snippet

(Where diskX is the disk corresponding to your USB Flash Drive).


4. We can now use dd to extract the image on to the disk.
Code Snippet
  1. sudo dd if=ubuntu-11.10-desktop-i386.img of=/dev/diskX bs=1m
End of Code Snippet

(Where diskX is the disk corresponding to your USB Flash Drive). This step may take a while depending on the size of the image.


5. Eject the flash disk using diskutil.
Code Snippet
  1. diskutil eject /dev/diskX
End of Code Snippet


(Where diskX is the disk corresponding to your USB Flash Drive).


You can now boot directly from the USB into your loaded operating system. Remember to go into the BIOS on the host system and change the Boot Priority, making the USB Flash Drive higher than the host HDD itself.



Windows

Windows users have a few options, you can repeat the above steps with a verison of dd for windows, however I have found that the following method is by far easiest!

1. Download your required operation system (.iso, .img etc)

2. Download Linux Live USB Creator

3. Launch Linux Live USB Creator, specify the OS image, the target Flash Drive (make sure its plugged in) and simply click the Lightning logo. All done!


You can now boot directly from the USB into your loaded operating system. Remember to go into the BIOS on the host system and change the Boot Priority, making the USB Flash Drive higher than the host HDD itself.

Manually remove Oracle installation from Linux


Stop all the databases and listener on the box either manually or using your startup script
Code Snippet
  1. /etc/init.d/oracle stop
End of Code Snippet


You can view all oracle processes using the command, this will search all running processes that begin with 'ora'.
Code Snippet
  1. ps -ef | grep ora
End of Code Snippet


Kill the relevent processes using the process' PID and the kill command
Code Snippet
  1. kill <PID>
End of Code Snippet


Remove all files within your $ORACLE_BASE directory (Don't forget to re-create this directory structure on a new install)
Code Snippet
  1. rm -rf $ORACLE_BASE
End of Code Snippet


Remove all Oracle references in etc
Code Snippet
  1. rm -rf /etc/ora*
End of Code Snippet


Remove any temporary files
Code Snippet
  1. rm -rf /tmp/.oracle
  2. rm -rf /var/tmp/.oracle
End of Code Snippet


This should be enough to remove Oracle from the machine...

Tuesday 24 April 2012

cron/crontab Task Scheduler - HOW TO


cron
cron is a time-based job scheduler in Unix-like computer operating systems. cron enables users to schedule jobs (commands or shell scripts) to run periodically at certain times or dates. It is commonly used to automate system maintenance or administration, though its general-purpose nature means that it can be used for other purposes, such as connecting to the Internet and downloading email.


To view the cron list on your current OS, execute the following command...
Code Snippet
  1. crontab -l
End of Code Snippet


The cron list above shows you which jobs are currently runing on your system. It may be totally empty, or it may have some jobs in there. Lets take a look at adding jobs to the cron list.


Adding jobs to the cron list
The cron list is like a plain text file... the location of this depends of what OS you are running. However, we can simply edit the cron list by executing the following command...
Code Snippet
  1. crontab -e
End of Code Snippet

If you cannot view the cron list, then you may need to set the EDITOR environment variable to your default editor (nano, vi etc...)


Now we have the cron list in view, lets look at adding a job...

All jobs in the cron list take the following format (We can also forward the output to another process, we'll look at this later).



 *   *    *   *   *    Command to be executed
┬   ┬  ┬  ┬  ┬
│ │ │ │ │
│ │ │ │ │
│ │ │ │ └───── day of week (0 - 6) (0 is Sunday, or use names)
│ │ │ └────────── month (1 - 12)
│ │ └─────────────── day of month (1 - 31)
│ └──────────────────── hour (0 - 23)
└───────────────────────── min (0 - 59)


Lets take a look at this example...
30 22 * * * /usr/local/bin/TenThirtyScript.sh >>/usr/local/CronLog.log 2>&1

This cron entry will execute the "TenThirtyScript.sh" script every day at 22:30... It will also store all of the scripts output in the "CronLog.log" file (useful for debugging cron entries!)

Extra Info (What does 2>&1 mean?)
2 is the default file descriptor for stderr.
1 is the default file descriptor for stdout.
>& is shell syntax for "fold a file descriptor into another"


Special Characters
We can also schedule more complex cron jobs using some special characters.

Asterisk ( * )
The asterisk indicates that the cron expression will match for all values of the field; e.g., using an asterisk in the 4th field (month) would indicate every month.

Slash ( / )
Slashes are used to describe increments of ranges. For example 3-59/15 in the 1st field (minutes) would indicate the 3rd minute of the hour and every 15 minutes thereafter. The form "*/..." is equivalent to the form "first-last/...", that is, an increment over the largest possible range of the field.

Percent ( % )
Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.

Comma ( , )
Commas are used to separate items of a list. For example, using "MON,WED,FRI" in the 5th field (day of week) would mean Mondays, Wednesdays and Fridays.

Hyphen ( - )
Hyphens are used to define ranges. For example, 2000-2010 would indicate every year between 2000 and 2010 CE inclusive.

L
'L' stands for "last". When used in the day-of-week field, it allows you to specify constructs such as "the last Friday" ("5L") of a given month. In the day-of-month field, it specifies the last day of the month.

W
The 'W' character is allowed for the day-of-month field. This character is used to specify the weekday (Monday-Friday) nearest the given day. As an example, if you were to specify "15W" as the value for the day-of-month field, the meaning is: "the nearest weekday to the 15th of the month". So if the 15th is a Saturday, the trigger will fire on Friday the 14th. If the 15th is a Sunday, the trigger will fire on Monday the 16th. If the 15th is a Tuesday, then it will fire on Tuesday the 15th. However if you specify "1W" as the value for day-of-month, and the 1st is a Saturday, the trigger will fire on Monday the 3rd, as it will not 'jump' over the boundary of a month's days. The 'W' character can be specified only when the day-of-month is a single day, not a range or list of days.

Hash ( # )
'#' is allowed for the day-of-week field, and must be followed by a number between one and five. It allows you to specify constructs such as "the second Friday" of a given month.[citation needed]

Question mark ( ? )
Note: Question mark is a non-standard character and exists only in some cron implementations. It is used instead of '*' for leaving either day-of-month or day-of-week blank.


Here are some more examples...

23:00:00 every weekday night
0 23 * * MON-FRI /usr/local/bin/TestScript.sh >/dev/null 2>&1

In 2003 on the 11th to 26th of each month from January to June every third minute starting from 2 past 1am, 9am and 10pm
2-59/3 1,9,22 11-26 1-6 * 2003 /usr/local/bin/TestScript.sh >/dev/null 2>&1


Note: ">/dev/null" forwards the output to a bottomless pit! Useful if you want to remove trace of the output completely.



cron Permissions
The following two files play an important role:

/etc/cron.allow - If this file exists, then you must be listed therein (your username must be listed) in order to be allowed to use cron jobs.

/etc/cron.deny - If the cron.allow file does not exist but the /etc/cron.deny file does exist, then you must not be listed in the /etc/cron.deny file in order to use cron jobs.

Please note that if neither of these files exists, then depending on site-dependent configuration parameters, only the super user will be allowed to use cron jobs, or all users will be able to use cron jobs.....



Saving Changes
Once you have made all the changes to the cron list file, save the file (I.e. !wq in vi)

You will now need to restart the cron service to pick up your changes.
Code Snippet
  1. /etc/init.d/cron stop
  2. /etc/init.d/cron start
End of Code Snippet


This command depends on which OS you are running.... See this link for restarting services on various distros of Linux: http://theos.in/desktop-linux/tip-that-matters/how-do-i-restart-linux-network-service/

Wednesday 18 April 2012

Apple/iTunes - Create an App Store account for another country (US/UK etc...)


This is useful if you would like to use an app on your iPhone or iPad only available in a certain country.

1. Change your country setting in the app store
http://downloadsquad.switched.com/2010/03/05/how-to-create-a-us-itunes-app-store-account-when-youre-not-in-t/

2. Create a new app store account without credit card
http://support.apple.com/kb/HT2534

3. Search for the application you would like and add it to your downloaded apps.

4. Sync your apps with your iPhone... All done!

Monday 2 April 2012

The folder "iTunes" is on a locked disk or you do not have write permissions for this folder.


Problem: iTunes requires write access to the iTunes directory located in your local user's music directory.

MAC OS X
1. Navigate to /Users/home/Music
2. Command+i on the iTunes directory (Opens the directory info)
3. Click the padlock in the bottom right and enter administrator credentials for the local machine...
4. Add your current user to the list of users with access (If it's not currently there)
5. Open the 'Privilege' dropdown for the current user, and select 'Read & Write'.
6. Click the padlock to lock the permissions.
7. Restart iTunes.


Windows
I don't have a Windows machine handy at the moment, but the process will be similar...

1. Navigate to 'My Documents' for the current user.
2. Right click and Properties for the iTunes directory (Either in here, or in the 'My Music' directory.
3. Set write permissions for the logged in user.
4. Restart iTunes.

Mac OS X - Package Management with MacPorts


MacPorts
The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the Mac OS X operating system.

You can obtain MacPorts from the download page as a package (For Lion, Snow Leopard and Leopard - At time of writing) or you can build from source.
This will typically be installed into /opt/local/bin, so make sure this sits in your PATH.

Update MacPorts
Code Snippet
  1. port selfupdate
End of Code Snippet

View installed ports
Code Snippet
  1. port installed
End of Code Snippet

Search for ports
Code Snippet
  1. port search apache2
End of Code Snippet

Get information about a port
Code Snippet
  1. port info apache2
End of Code Snippet

Find out dependencies for a port
Code Snippet
  1. port deps apache2
End of Code Snippet

See what variations for a port are available (I.e. with/without SSL)
Code Snippet
  1. port variants apache2
End of Code Snippet

Install a port (-f = Force activation)
Code Snippet
  1. sudo port install -f apache2
End of Code Snippet

Clean an installed port
Code Snippet
  1. sudo port clean --all apache2
End of Code Snippet

Uninstall a port
Code Snippet
  1. sudo port uninstall apache2
End of Code Snippet

Display files belonging to an installed port
Code Snippet
  1. port contents apache2
End of Code Snippet

Upgrade a port
Code Snippet
  1. sudo port upgrade apache2
End of Code Snippet


More information can be found on the official MacPorts Guide.