i really new in linux and just heard about shell scripting couple days ago..
i did exercises on linux in online tutorial but as a beginner, i'm facing problems in developing the script as there are errors that sometimes i dun have any idea on how to solve it.What i'm doing now is not homework, but i had been assigned to develop some system in linux.
i appreciate if there are people that willing to guide me on this matter.
my problem currently is on sub-string matter, where i need to read the line from file/directory and based on the line retrieved,i need to seperate the information in the line and assign as variable..
below are my script:
(the script reside in test.sh)
thus, the output something like this:
file_name successfully ran on Mon Jul 12 23:15:00 SST 2009.
now, what i need to do is to extract certain information from that line which is the name, date, time and the status
the desired output is:
name date time status
file_name Mon Jul 12 23:15:00 success
so,my next step is to identify the sub-string and assigned as variable first in order to parse the info and output it.
thus,my script is:
but i received error message which is
guide me please..
Last edited by pludi; 07-14-2010 at 03:55 AM..
Reason: code tags, please...
Your first line (shebang) should be
This:
is not valid POSIX sh syntax. It is valid in bash or ksh93. If you want that you need to change the first line to the desired shell. If you want to use POSIX shell, have a look here to see what is or is not allowed: Shell & Utilities: Detailed ToC
ok...i've edited my script and i got my desired output..
but the position of the string is always changes..Thus the script is no longer efficient.It may output wrong result. i'm thinking of creating a script that can read the exact sub-string that i wanted...let say from the whole line, i want to capture only "my file name"..instead of i have to set the position.
maybe in the log file, the last line has long/many words,so i just wanted to capture certain word in order for me to assign it as variable..
i've tried to search and did some try an error but still doesn't work.. any idea?
Last edited by pludi; 07-14-2010 at 03:55 AM..
Reason: code tags, please...
below are the scripts that i've edited based on my understanding:
the script output:
if success:
if failed:
BUT the output for name should be only "report_name" instead of "ERROR: report_name is" if failed
Moderator's Comments:
Use code tags, please...
---------- Post updated at 04:57 AM ---------- Previous update was at 03:51 AM ----------
one more question..
i wonder if is it possible if the date can be set as : 11 Jul 2010
based on script below,
the output is : "Tue Jul 11"
is there any other easier way to make the date as 11 Jul 2010 instead of i need to do step by step and combine the all the variable for example : echo "$day" "$month" "$year" ??
in addition, can someone guide me on how to eliminate day in front of the month " Tue Jul 11" as the day is changing from monday-sunday..
thanks.
Last edited by Scott; 07-15-2010 at 07:01 AM..
Reason: Code tags
Below is my ksh shell script where I need to check if variable fileprops is a subset of $1 argument.
echo "FILE PROPERTY: $fileprops"
echo "PARAMETER3: $1"
if ; then
echo "We are Good. $line FILE is found to be INTACT !! "
else
echo... (2 Replies)
Can some one please help me with the syntax in shell script for the below :
if $var1 exists in ('val1','val2','val3')
I want to execute a set of commands if the value of var1 variable matches any one of the given string values. Please let me know if there are any other option to go by.
... (10 Replies)
Hi All,
I am trying to to compare a string variable with a string literal inside a loop but keep getting the
./testifstructure.sh: line 6:
#!/bin/sh
BOOK_LIST="BOOK1 BOOK2"
for BOOK in ${BOOK_LIST}
do
if
then echo '1'
else
echo '2'
fi
done
Please use next... (1 Reply)
Can someone tell me how I can do this?
e.g:
a=$(echo -e wert trewt ertert ertert ertert erttert
erterte
rterter
tertertert
ert)
How do i replace the STRING with $a?
I try this:
sed -i 's/STRING/'"$a"'/g' filename.ext
but this don' t work (2 Replies)
Apologies for the utter triviality of this question, but we all have to start somewhere! I've also tried searching but this question is pretty vague so I didn't (a) really know what to search for or (b) get many relevant hits to what I did search for.
Anyway, I'm in the process of self-teaching... (1 Reply)
Anyone knows how to set variable in TCL ?
let say i have a password variable and it will have different values.
set variable
and variable has different values like:
xxxx
yyyy
zzzz (0 Replies)
Hi ,
I have a line by line output as follows,for example output of ls
sample1
sample2
sample
i need to check if this output contains the exact string sample.If i use grep , it will find out all strings that contain sample as a part of their word.I dont want to do a pattern matching... (11 Replies)
okay, this shouldn't be difficult but I can't figure it out. How can I set a variable with another variable. I have the following:
foreach pe ($dir $sp)
set tpe = `echo $pe | grep M`
if ($tpe == M) then
set ${$pe} = M <--- This doesn't work
else
endif
end
In this case what... (2 Replies)
I'm having an issue when I export within my program. I'm getting the variable name, not the variable value. I have a configuration file (config.txt) that has the values of the variables set as so:
set -a
export ARCHIVEPOSourceDir="/interfaces/po/log /interfaces/po/data"
export... (2 Replies)