Please Interpret The Meaning Of This Command

Hi ,

Please explain what the below command means ..


Code:
if grep -c -i Y $INIFILE > /dev/null

I know what is the use of grep, it is used for finding a character or string in a file. But i could not understand the above form of grep command.

I am new to linux so this might be a simple question, but please throw some light on it.


Edited

And also please explain why they are creating a file in null in the below command

Code:
cat /dev/null > $DATA_DIR/$DATAFILE



Similar Content



Quick GREP Question..

Hey guys,

Something is puzzling me!

I saw someone use the grep in the following way and I'm not sure I understand what it does, and if there's any benefit to using it this way.

Code:
grep X.X.X.X /var/log/log.log | grep -v query

I checked the man file which confirmed that -v is relating to matching non grouping lines (which I'm not sure I fully understand either!) but I don't see any difference in the output of the above command versus the same command without the | grep -v query bit..

Why would you pipe grep into grep unless you were searching for something specific within the search results?

Does query mean something else?

How To Run A Command In Another Command?

I am not sure how to ask this, sorry.

if I had a code like this

Code:
# grep -a ": " md5list.txt | cut -f2,3 -d


How can I run the command basename for each line of the output?

basename {(grep -a ": " md5list.txt | cut -f2,3 -d )}


EDIT: A little more clarity on what im doing:
I didn't realize that 'md5sums' was a link to a nice formatted page. So I copied all packages here and put them into a text file. I decided to write a script that put all of these in that format.

So basically, even though I have already ran the md5sum -c 'md5sum-list' I still want to finish this small project because I am learning a ton.

Why Should I Always Use Chmod When Not As A Root User

System Info:

I have normal user in CentOS 7 whose name is "mostafa" (the name of the account).

I naturally have another user called root with all privileges. User "mostafa" is put into sudoers file, too.

The OS is installed in VmWare, so the system is all mine.

Problem:

Now I create a file with touch file.sh and put a command in it, but when I want to run it with Code:
sudo ./file.sh

, an error is shown that the command Code:
./file.sh

does not exist. But if I Code:
 sudo chmod 777 ./file.sh

then it gets run. My question is that, why should I use Code:
chmod 777

when I myself have created the file, and I am in sudoers.

Can anyone explain me why shuold I still use Code:
sudo chmod 777

when the creator of the file is me.

Script Not Getting Executed Via CRON

I have a small script1 scheduled via cron to run every 20 mins to invoke script2 if script2 is not running.
When i run script1 from cmd line it works fine but when it is scheduled via cron it doesn't work. Not sure what am i doing wrong here.
I even tried to use absolute path.

Script 1
Code:
#!/bin/sh
/bin/ps -ef |/bin/grep script2.sh |/bin/grep -v $$ > /dev/null 2>&1
if [ $? -ne 0 ]
then
/usr/bin/nohup /home/user1/script2.sh &
fi

CRON LOG :
Feb 9 17:00:01 server1 crond[29771]: (user1) CMD (/home/user1/chk_script1.sh >/dev/null 2>&1)
Feb 9 17:20:01 server1 crond[21095]: (user1) CMD (/home/user1/chk_script1.sh >/dev/null 2>&1)
Feb 9 17:40:01 server1 crond[11218]: (user1) CMD(/home/user1/chk_script1.sh >/dev/null 2>&1)
Feb 9 18:00:01 server1 crond[29961]: (user1) CMD(/home/user1/chk_script1.sh >/dev/null 2>&1)

CRON JOB :
00,20,40 * * * * /home/user1/chk_script1.sh >/dev/null 2>&1

Getting The Last Background Pid

Hi, I know that it is possible to get the last background pid using the $! command, however when I use it in my QT application I got a wrong result. Below follows an example where this procedure works
Code:
[linux@localhost ~]$ (sleep 6 && echo "A test") &
[1] 3312
[linux@localhost ~]$ echo $!
3312
[linux@localhost ~]$ A test

Now my Qt application, where I got a wrong result:
Code:
./dbsync &>/dev/null &
[1] 5047
[linux@localhost comm5]$ echo $!
5047

but using the ps command it is possible to verify that the pid related to the right process is not the 5047 but 5050.
Generally it is the process that comes with the command Code:
echo $!

added of two.

I use QCoreApplication in my program. I do not know if it has something to do with this error.

Any advice is welcome

Searching For Strings

If there is one Windows XP feature that I greatly miss in Mint, it is the Search Companion.

I have been struggling with 'grep' in order to create something suitable but with limited success. Take the following problem:-

I wish to interrogate the folder home/dell/Documents/Domestic/Recipes, searching for all files containing the word "mushroom" or "mushrooms", ignoring case. (I can manage the latter. )

Each individual file search should terminate at the first instance of a match and move to the next file. (Recursive, yeh?) Only the file names need to be listed and the output should be paged to allow for easier reading of long lists.

Several different types of file may be involved, including .doc, .odt, .txt .pdf, .htm and .rtf. It would be nice to include all of them in one command. (Wild card behaviour in grep is not entirely predictable - at least not for me.) Running a separate grep command for each different file type would be tedious.

A significant difficulty is that, if grep fails with a syntax, or run-time error, it generally reports the fact but it also has a habit of producing no output, perhaps not returning to the command prompt, whilst sitting inviting the user to decide what to do next. What makes this particularly frustrating is that some file types might not be amenable to a grep search. Text in .txt files and, it would appear, .doc files appears to be searchable but I suspect that .odt files might be more problematic. The snag in such circumstances is trying to interpret grep's response. Does a null return mean that no match was found or that the file format cannot be successfully interrogated? Such failure might not be apparent if the associated file names are simply excluded from the output list.

Apart from grep, is there any other software that would do the job? Sadly LibreOffice Writer seems to be lacking in this area.

Exporting Log Data To A File That Matches Stdout

hey guys,

Let's say I want to find out which log files have related ntp information in them. I use cat and grep to search through the files in /var/log and then export that to a file. this is the command...

# cat /var/log/* | grep ntp > /home/log.txt

The file created from this command will not include the directories the log entries are apart of. Why not? For example, if you do this same command without exporting to the /home/log.txt file it will show you in stdout which directory each log entry is in. Hope I'm making sense here. My question is, is there a clever way to export to a file in a way so that the file created is structured exactly like the stdout of the command below?

# cat /var/log/* | grep ntp

Cron Ignoring Changes Made In File

Hi,

i have a small problem on my system... I recently wrote a small bash script and added it via crontab -u root -e and it's executed as it should.
Then a few days after i did edit my bash script, but once it is run by cron it doesn't reflect the changes i made to the script. I did manually restart crond, tryed sync, moved my script, renamed it even rstart the server - no success.
If i run my script manually it returns me the expected output.
part of my script (/root/sd.sh):
Code:
#!/bin/sh

echo -n "Checking Raid... "
RAID=`tw-cli /c0/u0 show status | cut -c17-31 | grep -ci OK`
RAIDSTATUS=`tw-cli /c0/u0 show status | head -n1 | cut -c17-31`
if [ $RAID -eq 0 ]; then
  VERIFYING=`tw-cli /c0/u0 show status | cut -c17-31 | grep -ci VERIFYING`
  REBUILDING=`tw-cli /c0/u0 show status | cut -c17-31 | grep -ci REBUILDING`
  if [ $VERIFYING -eq 1 ]; then
    CURRENTSTATUS=`tw-cli /c0/u0 show verifystatus | head -n1 | cut -c46-49`
  fi
  if [ $REBUILDING -eq 1 ]; then
    CURRENTSTATUS=`tw-cli /c0/u0 show rebuildstatus | head -n1 | cut -c47-50`
  fi
  echo "Raid is busy (Raid $RAIDSTATUS$CURRENTSTATUS)"
  exit 1
fi
echo "Raid is idle (Raid $RAIDSTATUS)"

echo -n "Checking for logged in Users... "
USERS=`who | wc -l`
if [ $USERS -gt 0 ]; then
  echo "Users online"
  exit 1
fi
echo "None logged in"

crontab -l :
Code:
root@monster:~# crontab -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
*/10 * * * * /root/sd.sh | logger
*/30 * * * * /root/dropbox.sh > /dev/null

syslog:
Code:
Mar 21 09:10:01 monster /USR/SBIN/CRON[3998]: (root) CMD (/root/sd.sh | logger)
Mar 21 09:10:01 monster logger: Checking Raid... Raid is busy (Raid )
Mar 21 09:17:01 monster /USR/SBIN/CRON[4045]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Mar 21 09:20:01 monster /USR/SBIN/CRON[4105]: (root) CMD (/root/sd.sh | logger)
Mar 21 09:20:01 monster logger: Checking Raid... Raid is busy (Raid )
Mar 21 09:30:01 monster /USR/SBIN/CRON[4266]: (root) CMD (/root/sd.sh | logger)
Mar 21 09:30:01 monster /USR/SBIN/CRON[4265]: (root) CMD (/root/dropbox.sh > /dev/null)
Mar 21 09:30:01 monster logger: Checking Raid... Raid is busy (Raid )

when i run sh /root/sd.sh
Code:
root@monster:~# sh /root/sd.sh
Checking Raid... Raid is idle (Raid OK)
Checking for logged in Users... Users online
root@monster:~#

Any ideas why? - any help or thoughts appreciated

regards
Pat

Print Column With A String Using Awk Or Grep

Hi All,

Using grep command with a defined string, you will get the row. Can I get the column instead of row? For example,

the file content is as below:

AA BB
123 456
789 ABE

execute 'grep ABE file' will give you "789 ABE". Is there any way to get the column:
BB
456
ABE
?

Thank you very much.

Getting Variable Integer Values From Grep

I want to write a Python script. In order to write it I need to figure out how to access the values associated with my signal level and bit rate.

If I use the following command

Code:
iwconfig | grep 'Signal level'

I get:

eth0 no wireless extensions.

lo no wireless extensions.

Link Quality=70/70 Signal level= -38 dBm


Obviously, I don't want Signal level. I want whatever it happens to be. In this case, it happens to be -38. Ditto Bit Rate...How do I grab -38 from the command line?