Sponsored Content
Top Forums Shell Programming and Scripting Shell script to email based on flat file output Post 302315217 by apoorva on Monday 11th of May 2009 11:28:52 PM
Old 05-12-2009
Question Shell script to email based on flat file output

Hi All,

I am a newbee in unix but still have written a shell script which should trigger a mail based on certain conditions but the problem is that my file is not being read. Below is the code please advise. I do not know where is it failing.

Note $ and the no followed with it is the no of the column in the Flat file

Code:
HOME=/export/home/ls/report/
$ORACLE_HOME/bin/sqlplus -s user_name/password@database  < /export/home/ls/report/notification.sql  > /export/home/ls/report/filename.txt
cat /export/home/ls/report/filename.txt | 
while read line awk `
BEGIN {
NOTE='Do not respond to this email as it was generated via an automatic process'
}
{
if ( $3 = 'Status' ) (
Content= 'Please move the incident to next status'
if ($7 >= 0 && $7 <= 14 )
                {
                  printf ("\nmailx -r user_name@comapny.com -s "Incident Number :" ,$1 ,$36 ,"-c ",$28",$Content,$NOTE)>> /export/home/ls/report/initial1.txt
                }
  
if ($8 >= 15 && $8 <= 29 )
                {
                  printf ("\nmailx -r user_name@comapny.com  -s "FO Number :" $1 $36 -c $28")
                }
if ($9 >= 30  ) 
                {
                  printf ("\nmailx -r user_name@comapny.com  s %s",$36," %s", $28)
                }
  
  continue
 )            
}
END {
}`


Last edited by Yogesh Sawant; 05-12-2009 at 05:30 AM.. Reason: added code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

creating email based on an output

Hello folks. I need to create a script that looks at a certain output (list of full paths of files) and gets the owner's name (2nd position in the path, for example: /dirA/jsmith/blah1/more_blah/still_blah... etc) Gets the jsmith and greps the related file for jsmith and send that output to... (1 Reply)
Discussion started by: saswerks
1 Replies

2. Shell Programming and Scripting

urgent-extracting block data from flat file using shell script

Hi, I want to extract block of data from flat file. the data will be like this start of log One two three end of log i want all data between start of log to end of log i.e One two three to be copied to another file. This particular block may appear multiple times in same file. I... (4 Replies)
Discussion started by: shirish_cd
4 Replies

3. Shell Programming and Scripting

Merge lines in Flat file based on first 5 characters

Hi I have the fixed width flat file having the following data 12345aaaaaaaaaabbbbbbbbbb 12365sssssssssscccccccccc 12365sssss 12367ddddddddddvvvvvvvvvv 12367 vvvvv Here the first column is length 5 second is length 10 third is length 10 if the second or third column exceeds... (3 Replies)
Discussion started by: Brado
3 Replies

4. Shell Programming and Scripting

(Urgent):Creating flat file using sql script and sqlplus from UNIX Shell Script

Hi, I need help urgently for following issue. Pls help me to resolve this issue. I am calling sql script file(file1.sql) from UNIX Shell Script(script1.ksh) using sql plus and trying to create flat file that contains all records returned from SQL query in SQL script(file1.sql) I given... (6 Replies)
Discussion started by: praka
6 Replies

5. Shell Programming and Scripting

Shell Script to Reformat a flat file

Hi , I have a text file noname.txt containing 1000+ records like this. One of the record I have given below. Input will b e like this BOT: 2010/06/01 00:25:59 21 = "private" Access-Method = 31 NCC = GBR 01 = "340806@osiris.fr.ft" 04 =... (2 Replies)
Discussion started by: smalya
2 Replies

6. Shell Programming and Scripting

Extracting email addresses from a flat file

All, I have a flat file which contains an email address in every line. I am trying to find a way to extract all the email addresses delimited by comma (,). Can you please show me a way, it will be very helpful, thanks. (3 Replies)
Discussion started by: sed_beginner19
3 Replies

7. UNIX for Dummies Questions & Answers

Read a flat file, evaluate and create output. UNIX SCRIPT.

Hi all, I have a flat file as below; 470423495|1||TSA-A000073800||1|||1 471423495|1||TSA-A000073800||5|||5 472423495|1||TSA-A000073800||2|||7 473423495|1||TSA-A000073800||3|||3 I like to create a Unix script. The script have to valuate the last two columns, if the values are... (4 Replies)
Discussion started by: mrreds
4 Replies

8. Shell Programming and Scripting

SQL query in UNIX script - output in flat file

Hi, I never did this before... what I want to do is execute a SQL query from a unix script and redirect sql query's output to a flat file (comma separated one) without the header info (no column names). I would also want not to print the query's output to the screen. snapshot of my script:... (13 Replies)
Discussion started by: juzz4fun
13 Replies

9. Shell Programming and Scripting

Sort based on positions in flat file

Hello, For example: 12........6789101112..............20212223242526..................50 ( Positions) LName FName DOB (Lastname starts from 1 to 6 , FName from 8 to 15 and date of birth from 21 to29) CURTIS KENNETH ... (5 Replies)
Discussion started by: duplicate
5 Replies

10. Shell Programming and Scripting

Getting data from a flat file based on condition

Hi, I have a flaty file from which i am fetching few columns in tablular form as below code. Now i want to fetch the column 6 and 7 in below code only if it either of them is non zero.However below startement awk -F, '$6==0 && $7==0{exit 1}' ${IFILE} is not working..Not sure where is the... (36 Replies)
Discussion started by: Vivekit82
36 Replies
lshell(1)						      General Commands Manual							 lshell(1)

NAME
lshell - Limited Shell SYNOPSIS
lshell [OPTIONS] DESCRIPTION
lshell provides a limited shell configured per user. The configuration is done quite simply using a configuration file. Coupled with ssh's authorized_keys or with /etc/shells and /etc/passwd , it becomes very easy to restrict user's access to a limited set of command. OPTIONS
--config <FILE> Specify config file --log <DIR> Specify the log directory -h, --help Show help message --version Show version CONFIGURATION
You can configure lshell through its configuration file: On Linux -> /etc/lshell.conf On *BSD -> /usr/{pkg,local}/etc/lshell.conf lshell configuration has 4 types of sections: [global] -> lshell system configuration (only 1) [default] -> lshell default user configuration (only 1) [foo] -> UNIX username "foo" specific configuration [grp:bar] -> UNIX groupname "bar" specific configuration Order of priority when loading preferences is the following: 1- User configuration 2- Group configuration 3- Default configuration [global] logpath config path (default is /var/log/lshell/) loglevel 0, 1, 2, 3 or 4 (0: no logs -> 4: logs everything) logfilename - set to syslog in order to log to syslog - set log file name, e.g. %u-%y%m%d (i.e foo-20091009.log): %u -> username %d -> day [1..31] %m -> month [1..12] %y -> year [00..99] %h -> time [00:00..23:59] syslogname in case you are using syslog, set your logname (default: lshell) [default] and/or [username] and/or [grp:groupname] aliases command aliases list (similar to bash's alias directive) allowed a list of the allowed commands or set to 'all' to allow all commands in user's PATH allowed_cmd_path a list of path; all executable files inside these path will be allowed env_path update the environment variable $PATH of the user (optional) env_vars set environment variables (optional) forbidden a list of forbidden characters or commands history_file set the history filename. A wildcard can be used: %u -> username (e.g. '/home/%u/.lhistory') history_size set the maximum size (in lines) of the history file home_path (deprecated) set the home folder of your user. If not specified, the home directory is set to the $HOME environment variable. This variable will be removed in the next version of lshell, please use your system's tools to set a user's home directory. A wildcard can be used: %u -> username (e.g. '/home/%u') intro set the introduction to print at login passwd password of specific user (default is empty) path list of path to restrict the user geographically. It is possible to use wildcards (e.g. '/var/log/ap*'). prompt set the user's prompt format (default: username) %u -> username %h -> hostname prompt_short set sort prompt current directory update - set to 1 or 0 overssh list of command allowed to execute over ssh (e.g. rsync, rdiff- backup, scp, etc.) scp allow or forbid the use of scp connection - set to 1 or 0 scpforce force files sent through scp to a specific directory scp_download set to 0 to forbid scp downloads (default is 1) scp_upload set to 0 to forbid scp uploads (default is 1) sftp allow or forbid the use of sftp connection - set to 1 or 0 sudo_commands a list of the allowed commands that can be used with sudo(8) timer a value in seconds for the session timer strict logging strictness. If set to 1, any unknown command is considered as forbidden, and user's warning counter is decreased. If set to 0, command is considered as unknown, and user is only warned (i.e. *** unknown synthax) warning_counter number of warnings when user enters a forbidden value before getting exited from lshell. Set to -1 to disable the counter, and just warn the user. SHELL BUILTIN COMMANDS
Here is the set of commands that are always available with lshell: clear clears the terminal help, ? print the list of allowed commands history print the commands history lpath lists all allowed and forbidden path lsudo lists all sudo allowed commands EXAMPLES
$ lshell Tries to run lshell using default ${PREFIX}/etc/lshell.conf as configuration file. If it fails a warning is printed and lshell is interrupted. lshell options are loaded from the configuration file $ lshell --config /path/to/myconf.file --log /path/to/mylog.log This will override the default options specified for configuration and/or log file USE CASE
The primary goal of lshell, was to be able to create shell accounts with ssh access and restrict their environment to a couple a needed commands. In this example, User 'foo' and user 'bar' both belong to the 'users' UNIX group: User foo: - must be able to access /usr and /var but not /usr/local - user all command in his PATH but 'su' - has a warning counter set to 5 - has his home path set to '/home/users' User bar: - must be able to access /etc and /usr but not /usr/local - is allowed default commands plus 'ping' minus 'ls' - strictness is set to 1 (meaning he is not allowed to type an unknown command) In this case, my configuration file will look something like this: # CONFIURATION START [global] logpath : /var/log/lshell/ loglevel : 2 [default] allowed : ['ls','pwd'] forbidden : [';', '&', '|'] warning_counter : 2 timer : 0 path : ['/etc', '/usr'] env_path : ':/sbin:/usr/bin/' scp : 1 # or 0 sftp : 1 # or 0 overssh : ['rsync','ls'] aliases : {'ls':'ls --color=auto','ll':'ls -l'} [grp:users] warning_counter : 5 overssh : - ['ls'] [foo] allowed : 'all' - ['su'] path : ['/var', '/usr'] - ['/usr/local'] home_path : '/home/users' [bar] allowed : + ['ping'] - ['ls'] path : - ['/usr/local'] strict : 1 scpforce : '/home/bar/uploads/' # CONFIURATION END NOTES
In order to log a user's warnings into the logging directory (default /var/log/lshell/) , you must firt create the folder (if it doesn't exist yet) and chown it to lshell group: # addgroup --system lshell # mkdir /var/log/lshell # chown :lshell /var/log/lshell # chmod 770 /var/log/lshell then add the user to the lshell group: # usermod -aG lshell user_name In order to set lshell as default shell for a user: On Linux: # chsh -s /usr/bin/lshell user_name On *BSD: # chsh -s /usr/{pkg,local}/bin/lshell user_name AUTHOR
Currently maintained by Ignace Mouzannar (ghantoos) EMAIL
Feel free to send me your recommendations at <ghantoos@ghantoos.org> v0.9.15 March 13, 2012 lshell(1)
All times are GMT -4. The time now is 05:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy