Sponsored Content
Top Forums Shell Programming and Scripting Output of find command to variable? Post 302763709 by horhif on Wednesday 30th of January 2013 11:05:15 AM
Old 01-30-2013
Output of find command to variable?

Hi,

I'd like to assign the output of the find command to a variable.

What I need is to run the find command, and if it returns zero files, the program exits.

so i'm trying to assign the output of the find command to the $var1 variable....and then if this is less than one, I echo a message and exit.

So far I have:

Code:
find /apps//log -name 'tuesday*log' -mtime +1 -exec ls -lhrt {} \; > $var1
                 
                 if [ "$var1" -lt 1 ]
                 then
                    echo "No files found"
                    exit     
                else
                sleep 1
                fi

i'm getting [: : integer expression expected
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command output to a variable.

With cut -c 8-13 myfile, I am getting some numeric value. In my shell script I am trying to assign something like this, var=cut -c 8-13 myfile But at the time of execution I am getting -c is not found. If I dont assign, then script executes well. Can we not simply use the value from one... (8 Replies)
Discussion started by: videsh77
8 Replies

2. UNIX for Dummies Questions & Answers

ls command output to variable in script

Hi, I wrote a script to get the oldest file from a directory path (which is passed as a parameter to the script) ######################################################### XMLFILE_PATH={$1} cd $XMLFILE_PATH JPM_FILENAME = `(ls -tr User* | head -1)` #echo $JPM_FILENAME ###### END... (1 Reply)
Discussion started by: dsrookie
1 Replies

3. Shell Programming and Scripting

get characters from output of a command in a variable

Hi, i have two questions, I am new to programming 1. I have an output of a command and i want to get some specific part of it in a variable. i am trying sr=`some comand xyz| grep 'Last Changed Rev:' | cut -c19-` now variable sr gets a end of line character at end. output of the command... (3 Replies)
Discussion started by: muaz
3 Replies

4. UNIX for Dummies Questions & Answers

problem with output of find command being input to basename command...

Hi, I am triying to make sure that there exists only one file with the pattern abc* in path /path/. This directory is having many huge files. If there is only one file then I have to take its complete name only to use furter in my script. I am planning to do like this: if ; then... (2 Replies)
Discussion started by: new_learner
2 Replies

5. Shell Programming and Scripting

store the output of "find" command in a variable?

I intend to find the path/full location of a file(filename given by user thru "read filenme") using "find" or any other command and then store it's output in a variable for some other processing. But struggling to put all things together (i.e finding the fully qualified location of that file and... (4 Replies)
Discussion started by: punitpa
4 Replies

6. Programming

Command output into a variable

Hi, with this command: cu -l /dev/ttyACM0 -s 9600 > name.txt I put the output of the port in a txt Is posible to do the same (or similar) in a var directly, inside a C program? cu -l /dev/ttyACM0 -s 9600 > variable ? I have trying this withs pipes, but i dont know how to... (6 Replies)
Discussion started by: daaran
6 Replies

7. Shell Programming and Scripting

How to put output of one command into a variable

Hi, Let say I have these 3 files (state, list and myscript). I want to be able get the sample output like below when I run myscript. Any one know how to fix the code? TIA. ~~~~~~~~~~~~~~~ > cat /home/state CA > cat /home/list CA 100 50 20 AUS 120 61 10 > cat myscript... (6 Replies)
Discussion started by: joker_789us
6 Replies

8. Shell Programming and Scripting

how to save an output of a command in a variable

Hi, in shell script, i have the command swstart -p which returns an output. i want to store the output of this command into a variable. how i can do that excerpt from the script #!/usr/bin/ksh # # # # Program: swstart -p # # Description: Starts the sentinels on Slave server ... (4 Replies)
Discussion started by: lookinginfo
4 Replies

9. UNIX for Advanced & Expert Users

ls output into a read command as a variable

I'm working on a short BASH script on my Ubuntu box that will run powerpoint scripts with MS Powerpoint Viewer 2007 via WINE. I can run the presentation when I run it manually but what i'd like to do is have the script look for the newest file then run it. #! /bin/sh # Start the newest... (2 Replies)
Discussion started by: binary-ninja
2 Replies

10. Shell Programming and Scripting

How to get the output of a ISQL command in a variable?

I am trying to run a query which returns a sum value(a number). I want to get it in a variable so that i can refer to that variable in different places. when i am running the following command variable=`isql -Uuser -Sserver -Ppassword 1> select sum(count(*)) from xyz..abc where clm_id... (2 Replies)
Discussion started by: Sharma331
2 Replies
EXEC(3) 								 1								   EXEC(3)

exec - Execute an external program

SYNOPSIS
string exec (string $command, [array &$output], [int &$return_var]) DESCRIPTION
exec(3) executes the given $command. PARAMETERS
o $command - The command that will be executed. o $output - If the $output argument is present, then the specified array will be filled with every line of output from the command. Trailing whitespace, such as , is not included in this array. Note that if the array already contains some elements, exec(3) will append to the end of the array. If you do not want the function to append elements, call unset(3) on the array before passing it to exec(3). o $return_var - If the $return_var argument is present along with the $output argument, then the return status of the executed command will be written to this variable. RETURN VALUES
The last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru(3) function. To get the output of the executed command, be sure to set and use the $output parameter. EXAMPLES
Example #1 An exec(3) example <?php // outputs the username that owns the running php/httpd process // (on a system with the "whoami" executable in the path) echo exec('whoami'); ?> NOTES
Warning When allowing user-supplied data to be passed to this function, use escapeshellarg(3) or escapeshellcmd(3) to ensure that users can- not trick the system into executing arbitrary commands. Note If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends. Note When safe mode is enabled, you can only execute files within the safe_mode_exec_dir. For practical reasons, it is currently not allowed to have .. components in the path to the executable. Warning With safe mode enabled, the command string is escaped with escapeshellcmd(3). Thus, echo y | echo x becomes echo y | echo x. SEE ALSO
system(3), passthru(3), escapeshellcmd(3), pcntl_exec(3), backtick operator. PHP Documentation Group EXEC(3)
All times are GMT -4. The time now is 01:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy