Sponsored Content
Top Forums Shell Programming and Scripting Parse output path to set variable Post 302737263 by es760 on Wednesday 28th of November 2012 03:27:42 PM
Old 11-28-2012
Parse output path to set variable

I am looking to parse a text file output and set variables based on what is cropped from the parsing.

Below is my script I am looking to add this feature too.
All it does is scan a certain area of users directories for anyone using up more than X amount of disk space. It then writes to the output file and emails the output file when done to a number of people that is defined in the script.
I want it to also email the username found in the output file.
Below the script is a sample output of what is emailed.


Code:
#!/bin/bash
_dufile="/tmp/testing-results.log"
MAILTO=myname@mydomain.com

rm -rf /tmp/testing-results.log

du -m -s /home/project_A/users/* | perl -ne '@l = split();print "@l\n" if $l[0]>=1960' > /tmp/testing-results.log

if [ -s "$_dufile" ]
then
        echo "$_dufile has found user with over allowed data amount, emailing "
        cat /tmp/testing-results.log | mailx -s " Testing user exceeded 2GB limit Quota Notification" $MAILTO
else
        echo "$_dufile is empty."
fi

--------------------------
output file data in /tmp/testing-results.log :
Code:
39292 /home/project_A/users/jdoe
49200 /home/project_A/users/bsmith
89019 /home/project_A/users/rguy


Basically, I need to read the output of /tmp/testing-results seen above, and crop out everything except the username "jdoe" and "bsmith" and "rguy" and set each one to a variable. Then just plugging in those variables to my mailx list with a domain name added.

This will then send the output to myname@mydomain, and also the output sent to each person/user "jdoe" "bsmith" ect...

I'm sure there are a million ways of doing this and would highly appreciate any suggestions of the read and parse of my output file /tmp/testing-results


Thanks in advance.

Last edited by Scott; 11-29-2012 at 12:12 AM.. Reason: Code tags, please
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Set Path variable in c shell

I set my path environment variable in c shell, using the syntax below setenv PATH "${PATH}:/usr/local:/usr/local/bin" and placed this in $HOME/.login $HOME/.cshrc and /etc/.login /etc/.cshrc but when I issued echo $PATH or set command the output does not reflect changes made to... (5 Replies)
Discussion started by: hassan2
5 Replies

2. UNIX for Advanced & Expert Users

How does the PATH and MANPATH environment variable get set?

Hi, How does the PATH and MANPATH environment variable get set? I want to add "/opt/SUNWspro/bin" to the search path for all the users. Where can I access this variable. I know in my home directory, depend on which shell I use, there are files such as .profile and .cshrc which I can edit to... (3 Replies)
Discussion started by: vtran4270
3 Replies

3. UNIX for Dummies Questions & Answers

set variable PATH

Hi, i know that this topic discussed for many times but although i had researched them i couldnt succeed in my problem. i am following a step-by-step instruction guide and must do the following: ------------- To ensure access, set the path PATH $ORACLE_HOME/perl/bin:$PATH and set the Perl... (2 Replies)
Discussion started by: merope
2 Replies

4. AIX

How to set path for the EDITOR variable?

For some reason something has changing in my AIX environment where when I type: ACLEDIT filename ...I get: 3002-104 acledit: EDITOR environment variable must be full pathname I know I need to reset the EDITOR variables path to /usr/bin/vi but I can't remember the syntax anyone? (2 Replies)
Discussion started by: heprox
2 Replies

5. UNIX for Dummies Questions & Answers

PATH variable set incorrectly?

I've noted that in order to use commands like ifconfig, I have to prefix the commands with the directory. /etc/profile shows that the paths should be part of the PATH environment variable; any idea where the bug is? :confused: # /etc/profile # System wide environment and startup... (1 Reply)
Discussion started by: jon80
1 Replies

6. Shell Programming and Scripting

Unable to set my PATH variable

Hello All, Hope you can understand my problem from the below code. $ cat ~/.profile PS1=`whoami`@`hostname`':$PWD $ ' export PATH="$PATH:.:/logarchive/utility/util:/usr/sbin:" $ echo $PATH /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:.:/usr/sbin: $ echo $SHELL /usr/bin/ksh ... (6 Replies)
Discussion started by: sathyaonnuix
6 Replies

7. HP-UX

How to set PATH variable for all HP-UX users when they login using ssh?

Hello friends, I need to set PATH variable for all HP-UX users. I tried to implement it using /etc/profile and /etc/sshrc both none of them work. I don't see sshrc file anywhere. Please advise! TIA (4 Replies)
Discussion started by: prvnrk
4 Replies

8. Shell Programming and Scripting

Set variable to path that does not exist on local host

Can anyone suggest a workaround zone_5.org='/qaz/qwe/path/tns.osn' output /home/bingo/XXX_script.sh: line 180: zone_5.org=/qaz/qwe/path/tns.osn: no parent The path does not exist on the local machine, the allocation used to work till the server was upgraded. Red Hat Enterprise Linux... (2 Replies)
Discussion started by: squrcles
2 Replies

9. Shell Programming and Scripting

ksh - variable to be set to windows path issue

Greetings Experts, I need to pass a parameter to ksh and the value is windows path eg: sh abc.txt C:\Users\chill3chee\Desktop No matter I try with \ delimiter, still could not get this exact value assigned to the shell variable which was checked with echo. Tried with using... (2 Replies)
Discussion started by: chill3chee
2 Replies

10. Shell Programming and Scripting

Find a file and set path in variable?

Hi Folks - I was wondering if you could help convert batch code in Linux? For instance, I use the following piece of code in DOS to find a file/executable, and then the FULL path as a variable. ::-- If startMaxl.exe exists, set full path --:: for %%D in (c d e f g h i j k l m n o p q r s t... (4 Replies)
Discussion started by: SIMMS7400
4 Replies
Template::Alloy::Parse(3pm)				User Contributed Perl Documentation			       Template::Alloy::Parse(3pm)

NAME
Template::Alloy::Parse - Common parsing role for creating AST from templates DESCRIPTION
The Template::Alloy::Parse role is reponsible for storing the majority of directive parsing code, as well as for delegating to the TT, HTE, Tmpl, and Velocity roles for finding variables and directives. ROLE METHODS
parse_tree Used by load_tree. This is the main grammar engine of the program. It delegates to the syntax found in $self->{'SYNTAX'} (defaults to 'alloy') and calls the function found in the $SYNTAX hashref. The majority of these syntaxes use methods found in the $DIRECTIVES hashref to parse different DIRECTIVE types for each particular syntax. A template that looked like the following: Foo [%- GET foo -%] [%- GET bar -%] Bar would parse to the following AST: [ 'Foo', ['GET', 6, 15, ['foo', 0]], ['GET', 22, 31, ['bar', 0]], 'Bar', ] The "GET" words represent the directive used. The 6, 15 represent the beginning and ending characters of the directive in the document. The remaining items are the variables necessary for running the particular directive. parse_expr Used to parse a variable, an expression, a literal string, or a number. It returns a parsed variable tree. Samples of parsed variables can be found in the VARIABLE PARSE TREE section. my $str = "1 + 2 * 3"; my $ast = $self->parse_expr($str); # $ast looks like [[undef, '+', 1, [[undef, '*', 2, 3], 0]], 0] "parse_args" Allow for the multitudinous ways that TT parses arguments. This allows for positional as well as named arguments. Named arguments can be separated with a "=" or "=>", and positional arguments should be separated by " " or ",". This only returns an array of parsed variables. To get the actual values, you must call play_expr on each value. "dump_parse_tree" This method allows for returning a string of perl code representing the AST of the parsed tree. It is mainly used for testing. "dump_parse_expr" This method allows for returning a Data::Dumper dump of a parsed variable. It is mainly used for testing. "parse_*" Methods by these names are used by parse_tree to parse the template. These are the grammar. They are used by all of the various template syntaxes Unless otherwise mentioned, these methods are not exposed via the role. VARIABLE PARSE TREE
Template::Alloy parses templates into an tree of operations (an AST or abstract syntax tree). Even variable access is parsed into a tree. This is done in a manner somewhat similar to the way that TT operates except that nested variables such as foo.bar|baz contain the '.' or '|' in between each name level. Operators are parsed and stored as part of the variable (it may be more appropriate to say we are parsing a term or an expression). The following table shows a variable or expression and the corresponding parsed tree (this is what the parse_expr method would return). one [ 'one', 0 ] one() [ 'one', [] ] one.two [ 'one', 0, '.', 'two', 0 ] one|two [ 'one', 0, '|', 'two', 0 ] one.$two [ 'one', 0, '.', ['two', 0 ], 0 ] one(two) [ 'one', [ ['two', 0] ] ] one.${two().three} [ 'one', 0, '.', ['two', [], '.', 'three', 0], 0] 2.34 2.34 "one" "one" 1 + 2 [ [ undef, '+', 1, 2 ], 0] a + b [ [ undef, '+', ['a', 0], ['b', 0] ], 0 ] "one"|length [ [ undef, '~', "one" ], 0, '|', 'length', 0 ] "one $a two" [ [ undef, '~', 'one ', ['a', 0], ' two' ], 0 ] [0, 1, 2] [ [ undef, '[]', 0, 1, 2 ], 0 ] [0, 1, 2].size [ [ undef, '[]', 0, 1, 2 ], 0, '.', 'size', 0 ] ['a', a, $a ] [ [ undef, '[]', 'a', ['a', 0], [['a', 0], 0] ], 0] {a => 'b'} [ [ undef, '{}', 'a', 'b' ], 0 ] {a => 'b'}.size [ [ undef, '{}', 'a', 'b' ], 0, '.', 'size', 0 ] {$a => b} [ [ undef, '{}', ['a', 0], ['b', 0] ], 0 ] a * (b + c) [ [ undef, '*', ['a', 0], [ [undef, '+', ['b', 0], ['c', 0]], 0 ]], 0 ] (a + b) [ [ undef, '+', ['a', 0], ['b', 0] ]], 0 ] (a + b) * c [ [ undef, '*', [ [undef, '+', ['a', 0], ['b', 0] ], 0 ], ['c', 0] ], 0 ] a ? b : c [ [ undef, '?', ['a', 0], ['b', 0], ['c', 0] ], 0 ] a || b || c [ [ undef, '||', ['a', 0], [ [undef, '||', ['b', 0], ['c', 0] ], 0 ] ], 0 ] ! a [ [ undef, '!', ['a', 0] ], 0 ] Some notes on the parsing. Operators are parsed as part of the variable and become part of the variable tree. Operators are stored in the variable tree using an operator identity array which contains undef as the first value, the operator, and the operator arguments. This allows for quickly descending the parsed variable tree and determining that the next node is an operator. Parenthesis () can be used at any point in an expression to disambiguate precedence. "Variables" that appear to be literal strings or literal numbers are returned as the literal (no operator tree). The following perl can be typed at the command line to view the parsed variable tree: perl -e 'use Template::Alloy; print Template::Alloy->dump_parse_expr("foo.bar + 2")." "' Also the following can be included in a template to view the output in a template: [% USE cet = Template::Alloy %] [%~ cet.dump_parse_expr('foo.bar + 2').replace('s+', ' ') %] AUTHOR
Paul Seamons <paul at seamons dot com> LICENSE
This module may be distributed under the same terms as Perl itself. perl v5.10.1 2011-01-26 Template::Alloy::Parse(3pm)
All times are GMT -4. The time now is 09:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy