09-28-2011
Need help embedding Unix commands in a shell script
Hi Folks,
I have a text file which may or may not have any data.
I would like to email the file, via a Korn shell script, if the file is not empty.
I am fiddling around with the wc -l command, but no luck so far. The pseudo code is as follows
count=`wc -l test.txt`
if [$count > 0]
cat test.txt | mailx -s "Test File" email.yahoo.com
endif;
As of right now, the "count" variable has more information than required and the information is being saved as string and not as integer.
Can somebody please show me the exact syntax? or provide an alternate way of doing this?
Thanks in advance
rogers42
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi ,
I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell.
So scenario is that
- I need to have one shell script which is ran as a part of crontab
- in this shell script I need to do a... (2 Replies)
Discussion started by: hkapil
2 Replies
2. UNIX for Dummies Questions & Answers
I need to know these UNIX Shell Commands with the appropriate parameters.
List the files in current directory beginning with extension .har. (% ls .har)
View text file "hosts.copy" which spans multiple screens.
Execute the batch file "tapeeject.bat"
Copy all files from current... (2 Replies)
Discussion started by: pilgrimnoir
2 Replies
3. UNIX for Advanced & Expert Users
Hi,
I know that to create a pdf file I can use the txt2pdf command.
But if I would change an existing pdf file, by inserting lines in particular positions of this file, what can I use? And How? (3 Replies)
Discussion started by: fandwick
3 Replies
4. Shell Programming and Scripting
When my script deals with large input files like 22Gb or 18 GB the basic commands like sort or join fails when run from inside the shell scripts. Can there be any specific reason for this?
For e.g.
sort -u -t "," -k1,1 a.csv > a.csv.uniq"
sort -u -t "," -k1,1 b.csv > b.csv.uniq"
The... (3 Replies)
Discussion started by: esha
3 Replies
5. UNIX Desktop Questions & Answers
Hello.
I found a Unix script on this site that calculates a date that is 2 months earlier from today. I'm using that script and writing the value to a file called 2monthsago.txt. I want to use that value in another script. Below is my attempt at doing that and the results.
My Script:
... (1 Reply)
Discussion started by: Colel2
1 Replies
6. Shell Programming and Scripting
can you help me to create a phone book with add, delete, modify with first name, last name, middle name, phone no(multiple ph no), address, email address, notes or comments to store about the contact and groups that hold for the contact..
i am new to this linux environment. please guide me.
... (1 Reply)
Discussion started by: monster11209
1 Replies
7. Homework & Coursework Questions
Hello, ive recently finished university and im working as an assistant teacher in a secondary school. ive been given the objective t o give the students an assignment with a simple shell program in C/C++ with the support for several commands the Shell must also have the ability of processing... (1 Reply)
Discussion started by: figureout
1 Replies
8. Shell Programming and Scripting
My webpage is hosted from perlscript(homepage.pl), i want to add piece of html code in the footer of the homepage. I simply pasted the html code at the end of the perl script as below...
========================================================
close(OUTSQL);
... (4 Replies)
Discussion started by: paventhan
4 Replies
9. UNIX for Dummies Questions & Answers
Hello. I need help trying to create a script in UNIX to do the following steps. I don't know which commands to input to achieve this.
1. In a directory tree, I want to duplicate all .txt files into the same directory, so 2 of each file exists in each directory where there is a .txt file
... (4 Replies)
Discussion started by: TitanTlaloc
4 Replies
10. Shell Programming and Scripting
Hi,
I wrote a simple script, which will call other scripts or run commands on a UNIX server. my script has multiple steps/commands with some delay in between.
I usually get some email notifications after the successful execution of each step.
**My intention is to get email alerts when it is... (5 Replies)
Discussion started by: System Admin 77
5 Replies
LEARN ABOUT DEBIAN
test::pop3
Test::POP3(3pm) User Contributed Perl Documentation Test::POP3(3pm)
NAME
Test::POP3 - Automate Email Delivery Tests
SYNOPSIS
use Test::POP3;
my $pop = Test::POP3->new({
host => $host,
user => $user,
pass => $pass,
});
# this will delete all messages from the server
ok($count == $pop->wait_for_email_count($count,$timeout),"got $count");
# find and delete a single email message which matches these rules
# see Test::Email for more information
$pop->ok({
# optional search parameters
to => ($is or qr/is like/),
from => ($is or qr/is like/),
subject => ($is or qr/is like/),
body => ($is or qr/is like/),
headername => ($is or qr/is like/),
}, "got message");
ok($pop->get_email_count() == $count, "$count emails in cache");
# get the Test::Email object
my @email = $pop->get_email();
ok($pop->delete_all() == 2, "deleted 2 messages");
# tweak MIME::Parser settings
my $parser = $pop->get_parser();
DESCRIPTION
Please note that this is ALPHA CODE. As such, the interface is likely to change.
This module can help you to create automated tests of email delivered to a POP3 account.
Messages retrieved from the server but not yet matched by a test will be cached until either that message is the first to pass a test, or
is returned by "$pop3->get_email()". Messages returned are Test::Email objects.
METHODS
"my $pop = Test::POP3->new($href);"
The arguments passed in the href are host, user, and pass.
"my $count = $pop->wait_for_email_count($count, $timeout_seconds?);"
Calling this method will result in all messages being deleted from the server. This will wait up to $timeout seconds for there to be
$count unprocessed messages found on the server. After $count or more messages are found, or after $timeout seconds, the current email
count will be returned. $timeout_seconds defaults to 30.
"my @email = $pop->get_email();"
Get all of the email messages currently in local cache. You should call "$pop3->wait_for_email_count($count)" before calling this
method if you think that there may be messages on the server yet to be retrieved. Calling this method will cause the local cache to be
emptied. Email messages returned will be Test::Email objects.
"my $count = $pop->get_email_count($check_server);"
This will return the number of email messages in the cache. If $check_server is true, then the server will be checked once before the
count is determined. If you would like to wait for messages to arrive on the server, and then be downloaded prior to counting, use
"$pop3->wait_for_email_count()".
"my $ok = $pop->ok($test_href, $description);"
Calling this method will cause the email in the local cache to be tested, according to the contents of $test_href. The first email
which passes all tests will be deleted from the local cache. Since this method only checks the local cache, you will want to call
"$pop3->wait_for_email_count()" before calling this method. "ok" will produce TAP output, identical to "Test::Simple::ok" and
"Test::More::ok".
"my $parser = $pop->get_parser();"
Test::POP3 uses MIME::Parser to process the messages. (MIME is not yet handled by "Test::Email", it will be soon.) Use this method if
you want to manage the parser.
EXPORT
None.
SEE ALSO
Test::Builder, Test::Simple, Test::More, MIME::Parser
AUTHOR
James Tolley, <james@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2007 by James Tolley
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or,
at your option, any later version of Perl 5 you may have available.
perl v5.10.0 2008-10-24 Test::POP3(3pm)