How to get the release value from an RPM -qi command - bash

I'm on RedHat, I need to get the value in the Release field.
Take "wget" for an example.
Here's the output I'm expected to get
WGET: 1.4.el6
Here's the output from rpm -qi wget
[luke#machine ~]# rpm -qi wget
Name : wget Relocations: (not relocatable)
Version : 1.12 Vendor: Red Hat, Inc.
Release : 1.4.el6 Build Date: Mon May 10 14:56:18 2010
Install Date: Wed Oct 3 16:48:58 2012 Build Host: x86-012.build.bos.redhat.com
Group : Applications/Internet Source RPM: wget-1.12-1.4.el6.src.rpm
Size : 1877597 License: GPLv3+ and GFDL
Signature : RSA/8, Mon Aug 16 21:21:35 2010, Key ID 199e2f91fd431d51
Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
URL : http://wget.sunsite.dk/
Summary : A utility for retrieving files using the HTTP or FTP protocols
How can I write a script to extract the "1.4.el6" from the Release field.
I currently have
#!/bin/bash
RELwg= rpm -qi wget
# Do string manipulation of $RELwg here
wg="WGET: "
echo $wg$RELwg
But here's the output I get;
Release : 1.4.el6 Build Date: Mon May 10 14:56:18 2010
WGET:
I know I have to do some string extraction, to get the number.
Get the index of the 1, seems to always be constant at 15
Get the index of the B in Build Date
Get the sub string inbetween 15 and whatever B is
Removing the space between "RELwg= rpm -qi wget" in my current script, I just get an error saying that
./GetRPMVersions.sh: line 12: -qi: command not found
Mainly my current predicament is to addign the ouput of rpm -qi wget | grep Release to a variable.
Any input on the string manipulation is welcome.

something like
RELwg=$(rpm -qi wget | awk -- '/^Release/ { print $3 }')

How about this:
RELwg=$(rpm -q --queryformat='%{RELEASE}' wget)

Related

How to use sed or awk or grep to find an email in a file that starts with the word "abuse"?

Ubuntu 16.04
GNU bash, version 4.4.0
I need to extract the email in a file that starts with the word abuse .
Here is a file that contains the whois information for an ip address and has the email abuse#web.ad.jp inside of it.
% [whois.apnic.net]
% Whois data copyright terms http://www.apnic.net/db/dbcopyright.html
% Information related to '121.92.0.0 - 121.93.255.255'
% Abuse contact for '121.92.0.0 - 121.93.255.255' is 'hostmaster#nic.ad.jp'
inetnum: 121.92.0.0 - 121.93.255.255
netname: InfoWeb
descr: FUJITSU LIMITED
descr: 17-25, SHINKAMATA 1-CHOME, OTA-KU,
descr: TOKYO 144-8588, JAPAN
country: JP
admin-c: JNIC1-AP
tech-c: JNIC1-AP
status: ALLOCATED PORTABLE
remarks: Email address for spam or abuse complaints abuse#web.ad.jp
mnt-by: MAINT-JPNIC
mnt-irt: IRT-JPNIC-JP
mnt-lower: MAINT-JPNIC
last-modified: 2015-12-01T22:23:26Z
source: APNIC
irt: IRT-JPNIC-JP
address: Urbannet-Kanda Bldg 4F, 3-6-2 Uchi-Kanda
address: Chiyoda-ku, Tokyo 101-0047, Japan
e-mail: hostmaster#nic.ad.jp
abuse-mailbox: hostmaster#nic.ad.jp
admin-c: JNIC1-AP
tech-c: JNIC1-AP
auth: # Filtered
mnt-by: MAINT-JPNIC
last-modified: 2017-10-18T10:21:54Z
source: APNIC
I am not concerned about which command extracts the email address of abuse#web.ad.jp from the file, I'm only concerned that it does it efficiently.
In the past I have used grep to find all email addresses within a file like ...
grep -o '[[:alnum:]+\.\_\-]*#[[:alnum:]+\.\_\-]*' "$1" | sort | uniq -i
But never an email that starts with a word, so my expected output from the command would yield me abuse#web.ad.jp.
$ grep "abuse[a-z]*#[a-z\.]\+" -o <filename>
Works assuming your e-mail doesn't include numbers or capitalized letters.

Displaying files under added directory through a merge in svn log

When using "svn log -v" directories that were added through a merge from a different branch show a merge reference, and all files contained within are omitted. Is there an easy way to display those files other than running the log command for the reference revision in the source branch?
IE:
$ svn commit -m "Added example dir"
Adding dir
Adding dir/a
Adding dir/b
Transmitting file data ..done
Committing transaction...
Committed revision 16.
$ svn update
Updating '.':
At revision 16.
$ svn log -v -l 1 .
------------------------------------------------------------------------
r16 | U3FS | 2018-01-08 17:21:22 -0600 (Mon, 08 Jan 2018) | 1 line
Changed paths:
A /lab/branches/source/dir
A /lab/branches/source/dir/a
A /lab/branches/source/dir/b
Added example dir
$ svn merge -c 16 ../source/ .
--- Merging r16 into '.':
A dir
A dir/a
A dir/b
--- Recording mergeinfo for merge of r16 into '.':
U .
$ svn commit -m "Merged example dir"
Sending .
Adding dir
Committing transaction...
Committed revision 17.
$ svn update
Updating '.':
At revision 17.
$ svn log -v -l 1 .
------------------------------------------------------------------------
r17 | U3FS | 2018-01-08 17:23:41 -0600 (Mon, 08 Jan 2018) | 1 line
Changed paths:
M /lab/branches/target
A /lab/branches/target/dir (from /lab/branches/source/dir:16)
Merged example dir
------------------------------------------------------------------------
I'd like to be able to see the addition of 'a' and 'b' under 'dir/' for r17 in the 'target' branch. I'm thinking I'm gonna need some bash magic to combine the logs, but trying to avoid writing something much more complex than it needs to be. All ideas welcome.
If I'm understanding what you're asking correctly, svn log -g should do what I think you're attempting to do, which is to look at the merge history.
svn log -vg if you'd like it verbose (I prefer this one).

How to find the date using internet (ie ntp) from bash?

How can I learn date and time from the internet using bash without installing anything extra.
I am basically looking for an equivalent of bash $ date, but using an NTP (or any other way) to get the correct date and time from the internet. All the methods I find (such as ntpd) are meant to correct the system time, which is not my purpose.
date has a lot of options for formatting, but I'm assuming that you just want the date and time:
ntpdate -q time.google.com | sed -n 's/ ntpdate.*//p'
(or any other time server)
If you have ntpd installed & configured then you can use the NTP Query command ntpq -crv which will return;
associd=0 status=04ff leap_none, sync_uhf_radio, 15 events, stale_leapsecond_values,
version="ntpd 4.2.6p5#1.2349-o Mon Feb 6 07:22:46 UTC 2017 (1)",
processor="x86_64", system="Linux/4.10.13-1.el6.elrepo.x86_64", leap=00,
stratum=1, precision=-23, rootdelay=0.000, rootdisp=1.000, refid=PPS,
reftime=dd2c9f10.f25911ee Wed, Aug 2 2017 19:57:20.946,
clock=dd2c9f11.f4251b0a Wed, Aug 2 2017 19:57:21.953, peer=6516, tc=4,
mintc=3, offset=-0.005, frequency=-17.045, sys_jitter=0.110,
clk_jitter=0.007, clk_wander=0.003, tai=37, leapsec=201701010000,
expire=201706010000
You want the line starting clock which gives the time, date etc - you would be best parsing this out with awk or something if you just want the date stamp rather then everything else.
You do not need to be a root user to run the command. It won't set anything, but will query your local server (presuming your running ntp) and present the details.

SVN command-line: Find current HEAD revision of a branch

As part of a script I'm writing, I'm trying to grab the latest revision number within a given branch in SVN.
I had tried the following code (where ${sourcebranch} is the SVN URL for my branch):
svn info ${sourcebranch} | awk '/Revision/ { print $2; }'
However, this seems to give me the latest revision number for the entire repository, not just the branch.
I really just want the branch... any ideas?
Use log instead:
svn log --limit 1 ${sourcebranch}
This will return the last commit to the branch, similar to this output:
------------------------------------------------------------------------
r14159 | author_name | 2014-04-25 18:54:49 -0400 (Fri, 25 Apr 2014) | 5 lines
log message
------------------------------------------------------------------------
From there, just parse the r#### field.
"Revision" value is applied to whole repo, you need "Last changed rev".

Use cat to combine mp3 files based on filename

I have a large number of downloaded radio programs that consist of 4 mp3 files each. The files are named like so:
Show Name - Nov 28 2011 - Hour 1.mp3
Show Name - Nov 28 2011 - Hour 2.mp3
Show Name - Nov 28 2011 - Hour 3.mp3
Show Name - Nov 28 2011 - Hour 4.mp3
Show Name - Nov 29 2011 - Hour 1.mp3
Show Name - Nov 29 2011 - Hour 2.mp3
Show Name - Nov 29 2011 - Hour 3.mp3
Show Name - Nov 29 2011 - Hour 4.mp3
Show Name - Nov 30 2011 - Hour 1.mp3 and so on...
I have used the cat command to join the files with great success by moving the four files of the same date into a folder and using the wildcard:
cat *.mp3 > example.mp3
The files are all the same bitrate, sampling rate, etc.
What I would like to do is run a script that will look at the file name and combine hours 1-4 of each date and name the file accordingly. Just the show name, the date and drop the 'Hour 1'.
I looked around and found a number of scripts that can be used to move files around based on their names but I'm not adept enough at bash scripting to be able to understand the methods used and adapt them to my needs.
I'm using Ubuntu 14.04.
Many thanks in advance
You can use a bash for loop to find each distinct date name and then construct the expected mp3 names from that.
Because your files have spaces in their names and my solution uses globbing, you'll also have to edit your Internal Field Separator to ignore spaces for the duration of the script.
SAVEIFS=$IFS
IFS=$'\n\b'
for mdy in `/bin/ls *mp3 | cut -d' ' -f'4,5,6' | sort -u`; do
cat *${mdy}*.mp3 > "showName_${mdy}_full.mp3"
done
IFS=$SAVEIFS
This won't alert you if some hours are missing for some particular date. It'll just join together whatever's there for that date.
Note: The comment pointing out that cat probably won't work for these files is spot on. The resulting file will probably be corrupted. You probably want to use something like mencoder or ffmpeg instead. (Check out this thread.)

Resources