Read Bash Script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Read Bash Script
# 1  
Old 08-10-2012
Bug Read Bash Script

I am very new to all these programming languages and really love Linux but have only begun to dive into bash scripting... I am curious what's going on with this script...

Code:
#!/bin/bash

if [ -e /proc/xen/capabilities ]; then
	# xen
	grep control_d /proc/xen/capabilities >& /dev/null
	if [ $? -ne 0 ]; then
	# domU -- do not run on xen PV guest
	exit 1;
	fi
fi

#safe to run mcelog
/usr/sbin/mcelog --ignorenodev --filter >> /var/log/mcelog

Thanks in advance! Smilie

Also I hope yo ucan forgive me as I just realised there is a thread for bash scripting haha PLEASE FORGIVE ME!!!!!!!!!!

Last edited by BrianBlaze; 08-10-2012 at 12:29 PM..
# 2  
Old 08-10-2012
See Reference Cards

-e means, check if a file or folder exists.

So, if /proc/xen/capabilities exists, it checks if the string control_d exists inside it.

If it doesn't, it quits immediately, not bothering to run the xen command on the bottom.

If it does, it doesn't quit, and continues through to the statement on the bottom.

So in effect, it only runs the statement on the bottom if control_d is found in /proc/xen/capabilities, or /proc/xen/capabilities doesn't exist.

It's done in a slightly awkward way. $? isn't needed. I'd just do this:

Code:
[ -e /proc/xen/capabilities ] && grep control_d /proc/xen/capabilities >& /dev/null || exit 1

#safe to run mcelog
/usr/sbin/mcelog --ignorenodev --filter >> /var/log/mcelog

&& is kind of a short-form if, || is a short form if-not. So, if /proc/xen/capabilities exists, AND control_d is not found inside it, exit immediately.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 08-10-2012
Awesome I can't wait until I am helping people like you! Have a great weekend!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

BASH script to read external file to perform text replacements?

Hi all, I have a moderate size (300 lines) BASH Shell script that performs various tasks on different source reports (CSV files). One of the tasks that it performs, is to use SED to replace 'non-conforming' titles with conformant ones. For example "How to format a RAW Report" needs to become... (3 Replies)
Discussion started by: richardsantink
3 Replies

2. Shell Programming and Scripting

Bash script read specific value from files of an entire folder

Hello, I heva a problem creating a script that read specifc value from all the files of an entire folder I have a number of email files into a directory and i need to extrect from each file 2 specific values. After that i have to put them into a new file that looks like that: To: value1 ... (1 Reply)
Discussion started by: ahmenty
1 Replies

3. Shell Programming and Scripting

'Couldn't read file' error in bash script with expect, sed and awk!

Ok, so I have a bash script with an embedded expect statement. Inside of the expect statement, i'm trying to pull all of the non-comment lines from the /etc/oratab file one at a time. Here's my command: cat /etc/oratab |sed /^s*#/d\ | awk 'NR==1'|awk -F: '{print \"$1\"}'|. oraenv Now,... (0 Replies)
Discussion started by: alexdglover
0 Replies

4. Shell Programming and Scripting

Help with grep and read function in a BASH Script

I'm putting together a script that will search my mail archives for emails that meet certain criteria and output the files to a text file. I can manually cat that text file and pipe it into sendmail and it will work (i.e. cat /pathtofile/foo.txt | sendmail -t me@company.com) My script sends... (7 Replies)
Discussion started by: binary-ninja
7 Replies

5. Shell Programming and Scripting

Bash script to read file location

I'm writing a bash script that reads a file location from a user, and I'm wondering how to get the script to accept tab to auto complete the directories that are input. (8 Replies)
Discussion started by: Prodiga1
8 Replies

6. UNIX for Dummies Questions & Answers

Cygwin bash script and read command

Hello everyone, I am struggling a bit with a batch script that I need to run in cygwin. I work in winXP and I had to write some awk scripts to do some file manipulation, and now I would like to automate the process by just running a batch file so that my colleagues can use it easily. Now, the... (2 Replies)
Discussion started by: Teroc
2 Replies

7. Shell Programming and Scripting

Bash Script to read a file and parse each record

Hi Guys, I am new to unix scripting and I am tasked to parse through a CSV file delimited by #. Sample: sample.csv H#A#B#C D#A#B#C T#A#B#C H = Header D = Detail Record T = Tail What I need is to read the file and parse through it to get the columns. I have no idea on how... (8 Replies)
Discussion started by: 3vilwyatt
8 Replies

8. Shell Programming and Scripting

BASH Shell script - help with read

Hi all, I'm sure this is quite a simple problem, but i'm completely new to shell scripting, so bare with me. Having problems with the read command. Here's what I have: read -rp "Command to execute: " the_command ... ... echo "$the_command" ... ... eval "$the_command" Now, say, for... (8 Replies)
Discussion started by: Justin Alvarez
8 Replies

9. Shell Programming and Scripting

Bash script to read a hostname and separate into variables

Hi All, I'm trying to concoct a bash script to use with a Puppet Implementation that will accept a hostname and break it down into variables. For example, my hostnames look like this --> machinename-group-building.example.com I'm looking for a way in the script to read until the first... (4 Replies)
Discussion started by: glarizza
4 Replies

10. Shell Programming and Scripting

Bash Script to Read & Write on different directories

Hi, root@server] df -h 121G 14G 101G 12% /home 147G 126G 14G 91% /backup We having our site files and images are storing in /backup/home/user/files/ through symbolic link created in /home directory pointing in /backup directory as following. root@server] cd /home... (1 Reply)
Discussion started by: mirfan
1 Replies
Login or Register to Ask a Question