Solved

Bash variable inside another varaible

Posted on 2010-09-20
2
179 Views
Last Modified: 2013-12-26
Looking to find out how to place a variable inside a variable.  The situation is this.  Every month a vulnerability scan is done using nessus and then exported to csv and I have a script to parse and clean out the know exceptions from the csv file.

Here is the initial script:

#### Variables
## Original Files
ORIG_FILE=File_090110_vulndata.csv
## Cleansed Files
NEW_FILE_CLEANSED=File_090110_vulndata_cleansed.csv
## Exceptions Files
NEW_FILE_EXCEPT=File_090110_vulndata_exceptions.csv

egrep -v "^.(40802|40803|40804|40805|42119|43875|44643|4550|44060|18405)" $ORIG_FILE > $NEW_FILE_CLEANSED

egrep "^.(Id|40802|40803|40804|40805|42119|43875|44643|4550|44060|18405)" $ORIG_FILE > $NEW_FILE_EXCEPT

Open in new window


Now what I am trying to do is include a variable which would include the date and use this new variable inside the file name so that every month one would just have to change the date in one spot.  Using this example the script would look like this:

#### Variables
MDATE=090110
## Original Files
ORIG_FILE=File_$MDATE_vulndata.csv
## Cleansed Files
NEW_FILE_CLEANSED=File_$MDATE_vulndata_cleansed.csv
## Exceptions Files
NEW_FILE_EXCEPT=File_$MDATE_vulndata_exceptions.csv

egrep -v "^.(40802|40803|40804|40805|42119|43875|44643|4550|44060|18405)" $ORIG_FILE > $NEW_FILE_CLEANSED

egrep "^.(Id|40802|40803|40804|40805|42119|43875|44643|4550|44060|18405)" $ORIG_FILE > $NEW_FILE_EXCEPT

Open in new window


However, this above code does not work and is the reason I am looking for assistance.
0
Comment
Question by:melod
2 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 33721678
Just needs braces

ORIG_FILE=File_${MDATE}_vulndata.csv
0
 

Author Comment

by:melod
ID: 33721748
LOL... thanks I tried everything but braces....  Glad you picked it up so fast.  Easy points for you. Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now