Wednesday, January 14, 2015

FTP Automation

This post will just give you a brief about how you can use FTP.

Normally we can use FTP in below way which is a normal standard.

$ftp -v HOSTNAME
> user USERNAME PASSWD
> [get][mget][put][mput] file / files
>bye
$

here -v stands for verbose mode which gives you details about each steps of how ftp client internally communicate with the host to connect successfully.

After providing userid passwd for to connect host, either you can pull/place the file/files. If you are dealing with single file then you can use get/put, for multiple files mget/mput.

As I said this is a standard way to do it, but how the industry use it.
Industry required, 
1. They don't want to provide userid/passwd, since it will be visible or security threat.
2. Make the FTP process automated
3. I don't want to provide userid / passwd while connecting to remote host.

Now how you can achieve this.
If you are going to connect xyz.com from your home a/c e.g. /home/vaibhav.
create .netrc file under /home/vaibhav/ directory.
Open file .netrc in any editor or vi editor and add below contents

machine xyz.com login your_userid password your_passwd 
Save the file and try the ftp again
Surprisingly it will directly connect you host xyz.com without providing userid/passwd

Industry standard discuss later is used is shell scripting also which makes automated stuff lot more easier.

I hope this is informative to you.

Monday, September 9, 2013

How to send mail using sendmail command

Hi All,

Before doing this make sure you have installed Sendmail on your malchine.

Now here the question is how to check whether the Sendmail is installed on your machine. If you are
using Linux Environment then please use the below command to identify the Sendmail availability.
$rpm -qa | grep sendmail
if you show some output as some sendmail rpm package name then it seems like it is installed.
You can cross refer the same using below command
$man sendmail
Now all set to go...
1) Create a file as xyz.sendmail
2) open and write 'xyz@example.com' in first line of file xyz.sendmail. Now this line indicate that 'xyz@example.com' is the receiver of this mail
3) open and write 'xyz@gmail.com' in second line of file xyz.sendmail. Now this line indicate that 'xyz@gmail.com' is mark as Cc in this mail.
4) open and write any valid "Subject" you want to mention for this mail in third line of file xyz.sendmail.
5) open and write BODY or Contents of your mail from fourth line onwords of file xyz.sendmail.
6) Once done, use the command as "sendmail -t < xyz.sendmail"

Please make sure that, your machine doesn't have any open relays otherwise your system become blacklisted so that then onwords you can't drop any mails. Also your system should have a fully qualified domain name and having DNS entry. This is must since the mail is going from your machine and 'From' field in the mail should be your machine domain name.

I hope this help you while programming means sending mails through script and also an alternative for mailx command.

Thanks & Regards
Vaibhav Wadkar

How to check whether the Autosys is up or down on your machine

Hi All,

I have provided some brief introduction about Autosys in my previous post.

In this post I will discuss about how to check whether Autosys is up or down on your machine. Suppose your machine name is "example.com". If you have Linux / Unix system then try below command on your machine

$ hostname

Once you got the machine name, try to execute below commands
$chk_auto_up

This command Verifies status of the  Unicenter  AutoSys  JM Scheduler and database. It determines if the Event Server (database) and the  scheduler are running. This is the utility you can use for debugging of Autosys. The output of this command is as below.

Logon to 201.32.02.19 - example.com (XYZ)
 chk_auto_up  
______________________________________________________________________________
CAUAJM_I_50054 Attempting (1) to Connect with Database: XYZ
CAUAJM_I_50055 *** Have Connected successfully with Database: XYZ. ***
______________________________________________________________________________
CAUAJM_I_50128 Connected with Event Server: XYZ
______________________________________________________________________________
______________________________________________________________________________
CAUAJM_I_50038 Checking CA Unicenter AutoSys JM Scheduler on Machine: example.com
CAUAJM_I_50044 Primary Scheduler is RUNNING on machine: example.com
______________________________________________________________________________
There is another command too which we can use while checking whether the Autosys is up or down.
Please use the below command to test.

$autoping -m example.com -A -D

This command verifies the connectivity  of  Unicenter  AutoSys Job Management (JM) server and client machines. This command also help us in debugging of Autosys. Here option -m stands for machine name, option -A sends an alarm when if any problem is detected, option -D check  the  database connections on the specified machine. Below shows the output of the command.

$autoping -m example.com -A -D
CAUAJM_I_50023 AutoPinging Machine [example.com] 
CAUAJM_I_50028 AND checking the Agent's DB Access.
CAUAJM_I_50025 AutoPing WAS SUCCESSFUL!

These are the heavily used Autosys command while debugging Autosys command. I hope this hope will help you while fixing Autosys.

Thanks & Regards
Vaibhav Wadkar

Saturday, August 31, 2013

What is Autosys

Hi,

This post gives you very brief introduction about Autosys. I will post some more details about Autosys in upcoming posts.

What is Autosys??
Autosys is an automated job control system for scheduling, monitoring, and reporting. This is developed by Unicenter.

A job is any single command, executable, script. Each job definition contains a variety of qualifying attributes, including the conditions specifying when and where a job should be run.

Autosys uses JIL (Job Information Language) as its own language. We can use this through a command -line interface. JIL is a specification language, with its own syntax, that is used to describe when, where,and how a job should run. When you enter the jil command, you get the jil command prompt, at which you can enter the job definitions one line at a time using this special language. When you exit the jil command -line interface, the job definition is loaded into the database. Alternatively, you can enter the definition as a text file and redirect the file to the jil command. In this case, the jil command activates the language processor, interprets the information in the text file, and loads this information in the database.

Sample from unix command prompt how to use this.

echo "insert_job:      xyz
      job_type:        c
      condition:       s(xyz)
      date_conditions: y
      command:         dbconnect.ksh (you can give any script name)
      machine:         machine name on which it needs to be run" | jil

Once done the XYZ job is getting added in Autosys. You can check it the same by using the below command on unix prompt.

$autorep -J XYZ

Make sure to run all this Autosys needs to be install first on your machine

Thanks

Shell Script to execute query by connecting Database

Hi All,

This post will give some idea about how to connect Database using shell script.

I am considering here an Oracle DB since it is used most widely in the industry. Along with Oracle, SQLPLUS is installed on your system. While connecting Oracle DB as a remote machine, please make sure you have SQLPLUS installed on your machine (i.e. from where you are connecting the DB or running this script).

You can simply test whether the SQLPLUS is installed on your machine as below.

$ sqlplus
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Sep 1 07:30:12 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Enter user-name:

If it is already installed then it will prompt username as above else will give you an error. Once you confirmed please try the below script (i.e. this is a sample query to show how to connect DB and execute the query)

#!/bin/ksh

#FileName: dbconnect.ksh

SQL="set feedback off underline off pages 0 lines 999 heading off
           select sysdate from dual;"

echo -e "$SQL"| sqlplus -s userid/password@TNSNAME

I have store the above script with name as dbconnect.ksh, here userid is the userid for your schema and password is the password used for the given userid. TNSNAME is nothing but the connection string you used to connect the DB.

Store the script and check if any syntx error using below command on command prompt

$ /bin/ksh -n dbconnect.ksh

Once having no error, please execute the below script by changing its permission
$chmod 775 dbconnect.ksh
$ /bin/ksh dbconnect.ksh

01-SEP-13


You can see the output as current date.

This is one of the way to execute the query, there are others ways to to connect the Database.
I hope this post is useful to you.

Thanks
 

Monday, May 9, 2011

Some Essentials



  • How to remove the control-M characters from file?
    File Ascci contains the text shown in below image. The commands shown in the image gives you the desire the output. If you want to save this output in differant file then redirect the desire output in differant file by using redirection operator i.e. '>'.
    Here are some different ways to achive the same result.......


  • command: 'cat Ascci.txt' shows you the content of the file.


  • command: 'cat -v Ascci.txt' shows you all the characters in your file.


  • command: 'sed 's/^M//g' Ascci.txt' substitutes / replaces the occurances of ^M with ''.


  • command: 'sed 's/\r\n//g' Ascci.txt' -- Actually ^M character forms with Carriage Return and a new Line Feed character means 'CR' & 'LF'. So in unix we can say for Carriage Return '\r' and for Line Feed '\n'. Hence substituting with \r\n also provides us the same result.


  • command: ' tr -d '^M' < Ascci.txt' -- here we are deleting ^M character from the output and not actually from the inputfile Ascci.txt


  • command: 'perl -p -e 's/^M//g' Ascci.txt' -- here we are running perl one liner. Here -p stand to print the output, -e stands for executes the remaining script. in single quotes we are again substituting ^M with '' globally with in entire file Ascci.txt. This also provides us the same desire result.


Tuesday, April 19, 2011

How to make a new partition on new hard disk

Hi All,

Please perform the following things, make sure you need to login as root first....

[root]# fdisk /dev/hdb
Command (m for help): m (Enter the letter "m" to get list of commands)
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 1
First cylinder (1-2654, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2654, default 2654):
Using default value 2654

Command (m for help): p

Disk /dev/hdb: 240 heads, 63 sectors, 2654 cylinders
Units = cylinders of 15120 * 512 bytes

Device Boot Start End Blocks Id System
/dev/hdb1 1 2654 20064208+ 5 Extended

Command (m for help): w (Write and save partition table)

[root]# mkfs -t ext3 /dev/hdb1
mke2fs 1.27 (8-Mar-2002)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2508352 inodes, 5016052 blocks
250802 blocks (5.00%) reserved for the super user
First data block=0
154 block groups
32768 blocks per group, 32768 fragments per group
16288 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root]# mkdir /opt2
[root]# mount -t ext3 /dev/hdb1 /opt2

I hope this helps for you...

Thanks...