LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-07-2019, 03:34 AM   #1
sampy12345
LQ Newbie
 
Registered: Jul 2017
Posts: 12

Rep: Reputation: Disabled
Shell script


Hi All,

I was trying to write a script and was trying to pass one of the variable as a file name in the script but unfortunately it is not working

When i am trying to run the file manually it is working (a blank file with unknown subject line is getting created)

Can anyone please help me

Below is the script

echo -e Message:$2 \ Device:$3 \ Category:$4 \ ErrorCondition:$1 \ Generatedat:$5 >> /tmp/warning.$(date +%Y%m%d-%H%M%S%s).txt
 
Old 02-07-2019, 03:57 AM   #2
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
It looks ok to me...
Can you provide us with more context i.e. the whole script and the variable values if not confidential?

NB: you shoud probably use this instead:
Code:
echo "Message:$2  Device:$3  Category:$4  ErrorCondition:$1  Generatedat:$5" >>/tmp/warning.$(date +%Y%m%d-%H%M%S%s).txt
 
1 members found this post helpful.
Old 02-07-2019, 04:24 AM   #3
sampy12345
LQ Newbie
 
Registered: Jul 2017
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by l0f4r0 View Post
It looks ok to me...
Can you provide us with more context i.e. the whole script and the variable values if not confidential?

NB: you shoud probably use this instead:
Code:
echo "Message:$2  Device:$3  Category:$4  ErrorCondition:$1  Generatedat:$5" >>/tmp/warning.$(date +%Y%m%d-%H%M%S%s).txt


Even after removing the -e we are unable to run the script.

My exact requirement is I have a NMS tool (Application Manager) and whenever a alert is raised i will be calling a script and in that script i will be passing arguments which are as below
$1 as message of the alert
$2 Severity of the alert
$3 OID
.
.
.
$6 eventid
.

Here my problem is when i am calling the script a file should be created with eventid

script i configured as
echo -e "Message:$2 Device:$3 Category:$4 ErrorCondition:$1 Generatedat:$5" >>/tmp/$6

output file to be created as

In tmp folder file should be created as

eventid

This is what i am trying to achieve
 
Old 02-07-2019, 04:41 AM   #4
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
^ You mean that you don't get a new /tmp/{eventid} file after your script has run?
By the way, you should use ">>/tmp/$6" (with double quotes) and you don't need -e echo switch in your instruction (as you don't use any backslash anymore)
 
Old 02-07-2019, 02:45 PM   #5
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,807

Rep: Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207
No, the >> is a redirection operator and must not be in quotes!
>> "/tmp/$6" or
>> /tmp/"$6" is okay.
It's good to have every $X in the script within double-quotes.
Further, I recommend a certain file extension.
For example
>> /tmp/"$6".event
Then later you can do operations with /tmp/*.event

Last edited by MadeInGermany; 02-07-2019 at 02:54 PM.
 
1 members found this post helpful.
Old 02-08-2019, 03:30 AM   #6
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
^ Of course I meant >>"/tmp/$6", not ">>/tmp/$6".
Thanks for the correction
 
Old 02-08-2019, 04:28 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,009

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
Quote:
Not working
This is a little unhelpful. Are you saying that no file is created? or that you are getting an error?

Could you please show an exact example (contrive the information if sensitive) of calling your script including a listing of the file location before and after and
any received messages
 
Old 02-11-2019, 10:45 AM   #8
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Re: "grail"'s suggestion...

Take a look at the script(1) command before you collect your information. Saves a lot of cutting and pasting.
Code:
$ script session.log

<issue your commands to create the "eventid" file, display its contents, etc.

^D
Then just post the contents of "session.log" into a "code" block.

For example:
Code:
$ script session.log
Script started, file is session.log
$ date
Mon Feb 11 10:42:07 CST 2019
$ uptime
 10:42  up 3 days 22:15,  9 users,  load average: 0,32, 0,54, 0,73
$ exit
Script done, file is session.log
$
$
$ cat session.log
Script started on 2019-02-11T10:42:04 CST
$ date
Mon Feb 11 10:42:07 CST 2019
$ uptime
 10:42  up 3 days 22:15,  9 users,  load average: 0,32, 0,54, 0,73
$ exit

Script done on 2019-02-11T10:42:13 CST
$
Great tool for passing test results back and forth.

HTH...
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script inside shell script treotan Linux - General 4 02-19-2009 06:34 AM
help with execute mulitple shell script within shell script ufmale Programming 6 09-13-2008 12:21 AM
how to get second shell script flag value from the first shell script amit_pansuria Programming 2 08-08-2008 08:19 AM
Call One shell script from another shell script Sundaram Linux - Software 5 10-13-2006 03:59 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration