Need help embedding Unix commands in a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help embedding Unix commands in a shell script
# 1  
Old 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
# 2  
Old 09-28-2011
use

Code:
wc -l < test.txt

Code:
 mailx -s "Test File" email.yahoo.com < test.txt 


# 3  
Old 09-28-2011
Quote:
Originally Posted by rogers42
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
If you're just trying to tell if the file is empty, you can do this:

Code:
[ -s "test.txt" ] && mailx -s "test file" email.yahoo.com < test.txt

-s means "file exists, and is not empty".
This User Gave Thanks to Corona688 For This Post:
# 4  
Old 09-28-2011
Code:
if [ -s test.txt ]; then echo "File exists and has size > 0"; fi

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
# 5  
Old 09-28-2011
Hi Folks,

Thanks to everybody who took the time to reply. And especially to the last two posters for sharing such elegant yet simple code.

Exactly, what I was looking for.

Thanks

rogers42
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script with mutiple steps/commands, on UNIX servers

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

2. UNIX for Dummies Questions & Answers

UNIX commands for a script that I need

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

3. Shell Programming and Scripting

Embedding HTML in Perl script

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

4. Homework & Coursework Questions

Unix shell commands

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

5. Shell Programming and Scripting

to create a phone book using shell script and unix commands

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

6. UNIX Desktop Questions & Answers

Embedding file output into a script

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

7. Shell Programming and Scripting

Unix commands failing inside the shell script

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

8. UNIX for Advanced & Expert Users

How to modify an existing pdf with unix shell commands

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

9. UNIX for Dummies Questions & Answers

UNIX Shell Commands Help . . .

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

10. Shell Programming and Scripting

How to run unix commands in a new shell inside a shell script?

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
Login or Register to Ask a Question