Index syndication
comment syndication

Archive for unix

Mailing attachments from the Solaris Shell

I needed a quick way to send some files from the command line when logged into a Solaris server via ssh.
This assumes the server is already configured to deliver your smtp mail. I also used mailx for the sending client.
Here is how I did it, for your geeky reference.

First write your message:
cat << EOF > /tmp/mailmsg
Hi this is a message
And this is the second line
EOF

Then populate your recipient list, comma delimited as per the mailx(1) man page:
cat << EOF > /tmp/mailrecipients
john.doe@nodomain.com.it,jack.black@someplace.co.za
EOF

  • Then the actual command that will send your mail
  • . You need to uuencode your binary attachments, and you can send as many as you need.
    (cat /tmp/mailmsg ; uuencode /path/to/file.txt file.txt ; uuencode /location/of/otherfile otherfile) | mailx -s 'Subject' -r myemail@some.place.mx `cat /tmp/mailrecipients`

    You need to specify each file name twice, once for source file to encode, and once for the encoded file name; as per the uuencode(1C) man page. If you are sending from some local account on the server, the -r switch allows you to specify an alternate return address for the recipients (in other words your normal email address).

    PS: watch for the quotes and backticks. Dont mix them up!

    Hope this helps you out someday.

    Clearcase Tips Number 03 - managing label conventions with perl

    I previously showed you how to use a shell script with Rational Clearcase, to alert you when a new branch type was created.

    In this post, I will show you how to use a Perl script to enforce Clearcase labeling conventions. Perl LogoThis example is directed toward Clearcase on UNIX (i.e. Solaris or similar) and assumes you have Perl installed, working and have a basic knowledge of how to program in Perl. It is a reworked version of the windows script supplied by IBM on Developerworks.

    This is a long post, but a good one if you are a new clearcase admin who needs to enforce label names.

    Read the rest of this entry »

    Unix Humour

    I came across (via an old school friend on facebook) something which I just had to share. I know whom will be laughing at this.

    Unix Humour

    Clearcase Tips Number 02 - Triggers and email

    I was looking for a simple way to have someone emailed when an event occurred in Rational Clearcase, like a new branch type being created. If you run Clearcase on UNIX (i.e. Solaris or similar) you can whip up a simple shell script and create your trigger. I will assume you have sendmail or similar already configured on your host so that mail utilities can send smtp mail

    Lets have a go at it.

    Write a shell script that uses mailx to send a message with some Clearcase trigger variables embedded in it, something like this:

    # Comma delimited email list of mail recipients
    adminmail="youraddress@your.domain.com"
    #This gets the host name
    host=`uname -a |awk '{print $2}'`
     
    #Begin send of message
    echo "\
    Creation of brtype \"$CLEARCASE_BRTYPE\"
    by: $CLEARCASE_USER
    comment: $CLEARCASE_COMMENT" \
    | /usr/bin/mailx -s "[$host:CLEARCASE] New branchtype $CLEARCASE_BRTYPE created"

    You can download this mail_new_brtype.sh if you are in a rush.

    In this script you will see a number of variables starting with $CLEARCASE. These variables will be populated as environment variables when a trigger event occurs and launches the shell script.

    The script should be saved somewhere it can be run on the UNIX server hosting the VOB, so when Clearcase triggers it can run the script. An appropriate location would be in the home directory of the VOB owner, for example:
    /home/ccadmin/ccscripts/mail_new_brtype.sh

    One you have saved the script, you need to actually make the trigger in Clearcase. Consider the following on creating this trigger type

    • We need the trigger to run after the event, this is what is known as a “Post Operation”
    • We want the trigger to be enacted after a new type is made, of type branchtype.
    • We want the trigger to execute our shell script on the event occurring

    You can research these options by viewing the man page of the command used to make a new trigger type:
    cleartool man mktrtype

    Once you have had a read of the man page, you should see some examples and options that can be used. Have a go at running the command yourself. This is what I came up with and should cover all our considerations:
    cleartool mktrtype -c "Trigger to email cfgmgr on new brtype creation" -type -postop mktype -brtype -all -exec /home/ccadmin/ccscripts/mail_new_brtype.sh new_branch_trigger
    My example shown here is relevant to Clearcase V6, so YMMV.

    Once that has been run, you can see your new trigger listed in the trigger type list:
    cleartool lstype -kind trtype
    18-Dec.10:27   ccadmin     trigger type "new_branch_trigger"
      "Trigger to email cfgmgr on new brtype creation"

    Next time a user creates a branch type, you will receive an email with the branch type name, branch type comment and whom created it!

    Look for more upcoming tips; including how to make a trigger use a perl script to validate label names.

    Perl while loop memory hog

    I was trying to use someone elses script for logging dansguardian events to an RDBMS.The script was chewing up 99% of my CPU! I got chatting to a friend and a perl coder about this, and got some ideas. He showed me about the perl debugger using the -d switch. Awesome. I finally got my perl script working. Installing the DBI package on OpenBSD was a snap with pkg_add (pkg_add -v p5-DBD-Pg-1.47.tgz). My logical debugging was as follows.

    first I read that DBI was a memory hog so I wrote it out and put in a native postgres call, but the pgsql for perl was borked.
    (comment from coding friend “DBI is fine man, works for the massess”). Next I changed the while loop over the the file to a Tail::File method, but the module was badly documenting and had issues.

    I actually ended up using IO::File to tail the log and looped over the lines (in a mad loop), but it was still broken.
    So I went back to DBI, which as my friend pointed out was never a problem. It worked!

    It turned out the loop was the CPU hog and all I had to do was put in a sleep 1; if there was no new line in the tail.
    In the process I rewrote the whole script and it barely resembles the original except for the idea. Now it has 0.5% CPU load at best. A win for coding. I’ll post the script soon and also send it to dansguardian.

    Comment from perl coding friend: of course - i guessed that after u left. :-)

    « Previous entries · Next entries »