I am trying to learn to write basic shell scripts. I have a little experience with perl but none with shell. I am trying to write a simple script to write the last 15 or so lines of log files for my web server to a temp file so I can view all at once. Here's what I have. Are you not able to use commands like tail or am I going about it wrong. I looked at some other scripts that used similar commands in a script the same way.
I forgot about the quotes too. Double quotes print exactly what in them, correct? The single allow me to define what to do?
cj- That is exactly what I wanted to do. Thanks much!
chubler- I made the semicolon changes and single quotes around my commands. The script now prints only the last command tail -n 15 /var/log/messages but puts a nice seperator tag. Why is it not picking up the other files? Compared to cj's code the only difference is the output to file at the end. Here's the new code and output. Thanks!
The issue is to do with how the shell does expansion/subsitution and word splitting.
Only brace expansion, word splitting, and filename expansion can change the number of words of the expansion; other expansions expand a single word to a single word
To work around this issue either pipe commands to another shell like cjcox did or use eval:
Got it. Thanks. What caused the header to show up and I have been struggling to get it to show before all of the files. In fact now that i wokrs correctly and displays all log file info, it doesn't show at all.
With the eval it works as I wanted. I guess I am probably better off switching to perl if I want to be more detailed like adding headers and dating the file. Thanks again for the quick response and explainations so I have something to read more about.
Hi Folks -
Is there a way to add two execs to one script? For instance, I need to redirect the stdout and stderr to two separate directories. I want to do this:
#::-- Direct STDOUT and STDERROR to repositories --::#
exec 2>"${_ERRORFILE}" > "${_LOGFILE}"
exec 2>"/new/path/file.err" >... (7 Replies)
Hi
script> isumid 98765432
if i give above command in cmd prompt it is running the same thing if i give inside the shell script it is not working
below is the code
#!/bin/bash
isumid 98765432
please give me a solution (16 Replies)
Hi all,
I am trying to use the Ex editor and its commands in a script - more specifically within an if statement within a while loop.
Here are the basics of the loop:
cat $file1 | while read line
do
grep $line $file2
if ]
then
echo $line > $file2
elseex $file2
/ESI185... (4 Replies)
I have a set of commands that I am using to copy specific areas of source code in a Cold Fusion document and export the code into recreations of the original files into a sub-directory. Here are the 3 commands I am using:
mkdir ./out && for x in *.cfm; do awk '{FS="<!-- InstanceBeginEditable... (17 Replies)
Can anyone help me out in visualizing on what is the logic behind simple unix commands. For Eg: ls command lists files and directories, how it displays I need to know the source code for commands like this. (1 Reply)
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)