Solved

script to read file

Posted on 2013-11-06
1
176 Views
Last Modified: 2014-07-10
Hi,

I have a file called storage.cfg, and would like to be able to list the directory if it contains a certain line.
sample file:

dir: local
        path /var/lib/vz
        content images,iso,vztmpl,rootdir
        maxfiles 1

nfs: OpenC1-prox
        path /mnt/pve/OpenF-prox
        server 1.1.1.1
        export /mnt/data/openf/ProxNFS
        options vers=3
        content images,iso,vztmpl,rootdir,backup
        maxfiles 2

nfs: OpenC1-voip
        path /mnt/pve/OpenF-voip
        server 1.1.1.1
        export /mnt/data/openf/ProxVoIP
        options vers=3
        content images,iso,vztmpl,backup,rootdir
        maxfiles 1

Open in new window


If I were to do it manually I would look for the lines after a (dir|nfs|iscsi|lvm) and if the content line contains vztmpl, then I need to grab the path, append /template/cache and run ls -l on the directory.  The indentations are tab characters.



ls-l /var/lib/vz/template/cache
ls -l /mnt/pve/OpenF-prox/template/cache
ls -l /mnt/pve/OpenF-voip/template/cache

I don't know where to start with this...

TIA,
Carlos.
0
Comment
Question by:carlosmp
1 Comment
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
Comment Utility
perl -00ne 'system "ls -l $1/template/cache" if /content.*vztmpl/ && /path\s+(.+)/' storage.cfg
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
EvenOdd challenge 10 81
VBA color chart bars 12 64
allStar challenge 1 41
parentbit challenge 3 51
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 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

10 Experts available now in Live!

Get 1:1 Help Now