RHEL7 Notes
systemctl <start|stop|reload-daemon|restart> <service>
/usr/lib/systemd/system/ - system service definitions
An idiot's guide to Linux - or nerd stuff I always forget.
Tuesday, July 26, 2016
Friday, May 1, 2015
Notes on Centos Network Install
Path to the install source must go down to the arch e.g.:http://mirror.internode.on.net/pub/centos/7/os/x86_84
The network interface much be enabled before the installer can set up the base repository.
The problem is the network config button is after the installer source button, so it is logical to try and set up the repo first.
However that won't work, instead you'll get a "error setting up base repository" warning/error.
So go to the network settings first and turn an interface on.
Sunday, December 7, 2014
How to su with a here doc
Not sure why, but it took me ages to work out the correct syntax to run su with a shell and a here document.
Turns out the correct syntax, or at least syntax that seems to work, is:
su - <user> -c /bin/bash <<-'EOF'
<some commands...>
EOF
Now this assumes we're running as root, else you'd need to enter a password.
EOF in the above example is just a delimter user to indicate where the here doc ends , it can be more or less any string, but I'd keep it alpha to keep things simple, i.e. avoid punctuation and the like.
e.g.
[root@clivm ~]# cat test.sh
#!/bin/sh
#run the 'id' command to show we're running as root
id
su - fred -c /bin/bash <<-'MEH'
#now run id to show we're runnning as fred and some echos
#to show where the user 'fred' session starts and ends
# fred's session starts and ends
echo "---running as ${USER}--"
id
echo "now I am fred:"
echo
echo "---about to hit the end delimiter and exit ${USER}'s context"
MEH
# show that we have left fred's context and are running as root again
id
echo "---running as ${USER}--"
The above example uses MEH as the delimiter.
When run as root it looks like this:
The bold section is executing as user fred.
[root@clivm ~]# sh test.sh
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
---running as fred--
uid=500(fred) gid=500(fred) groups=500(fred) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
now I am fred:
---about to hit the end delimiter and exit fred's context
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
---running as root--
[root@clivm ~]#
When run as root it looks like this:
The bold section is executing as user fred.
[root@clivm ~]# sh test.sh
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
---running as fred--
uid=500(fred) gid=500(fred) groups=500(fred) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
now I am fred:
---about to hit the end delimiter and exit fred's context
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
---running as root--
[root@clivm ~]#
Wednesday, September 24, 2014
Network Interfaces And The "ip" Command
With the release of RHEL 7 the long threatened removal of the ifconfig has finally come about.Ran into my first RHEL7 (Centos7 actually) box today while patching some VMs and had to work out the dreaded ip command.
In a nutshell
Assuming you have a machine that needs it's network configured nad it does not have any configured interface and you want to use the following details:
ip 10.10.10.23
gateway 10.10.10.1
netmask 255.255.255.0
network device: ens32
You can probably do it with these commands:
ip addr add 10.10.10.23/255.255.255.0 dev ens32
ip route add default via 10.10.10.1 dev ens32
View addresses with:
ip addr show
and routes with
ip route show
completely unsurprisingly deleting is...
ip addr del 10.10.10.23/255.255.255.0 dev ens32
ip route del default via 10.10.10.1 dev ens32
Anything cleverer is left as an exercise for the reader, because at this point in time I probably have NFI.
Hope it helps.
If not ask me a question. I might be able to answer it.
Sunday, August 31, 2014
More GNU date magic
More GNU Date Magic
Many unix users don't realise that the GNU date utility can be used for far more than simply getting and setting the time.
GNU date is a very versatile and handy utility for calculating, formatting and manipulating dates generally.
One of the things you need to know about that is that you can set the time and date that you want date to work on.
Basically there are two dates that date works with:
- now i.e. the time and date of execution or
- some other arbitrary date specified by the caller
To use now you often will not need to specify anything
e.g.
[jtan@clivm 0509]$ date
Mon Sep 1 11:50:28 CST 2014
returns the time and date that you executed the command.
In this case 11:50 and 28 seconds on Monday Sep 1 2014 CST (Central Standard Time)
But if I want to know the date for 60 days in the future and I am too lazy too count the days in the calendar or I want to use that in a script I can tell date to print that time.
The way you tell date to do it's work based on a time other than now is to use the -d option.
Now the real date magic is that the -d option is very flexible in the format of the options it will accept.
e.g. to find out the date and time 60 days from when I run the command I can run:
date -d "now + 60 days"
and it will give me
[jtan@clivm 0509]$ date -d "now + 60 days"
Fri Oct 31 12:55:48 CST 2014
Now I have used the keyword now to indicate that I want date to run using the time of execution as it's base time to use.
However that is actually redundant in this case, because now is actually the default, so date -d "+60 days" will also work. In fact date -d"60 days" will also work, which I think is about as minimal as you can go and still express the desired result.
However that is actually redundant in this case, because now is actually the default, so date -d "+60 days" will also work. In fact date -d"60 days" will also work, which I think is about as minimal as you can go and still express the desired result.
You can of course also pass date a format in the standard manner:
[jtan@clivm 0509]$ date -d "now 1 month" "+%d-%m-%Y"
01-10-2014
Sunday, August 24, 2014
Postgres's psql and schemas
When I was a lad and the ancestors of the dinosaurs had just emerged from the primordial soup, you could run the psql client with a named data base and just type something like:
select something, something_else, a_third_thing from some table_or_other;
And get a result.
Then along came schemas.
What's a schema? It's a namespace that allows tables within a database to be grouped.
Now when you run the above you'd get something like:
ERROR: column "something" does not exist
LINE 1: select something, something_else, a_third_thing from some_table_or_other;
This is because you need to specify the schema you want to search.
How do you know what schema to search?
Well you can list the tables and Postgres will by default show a column with the schema names, e.g.:
You can also list the schemas themselves e.g :
select something, something_else, a_third_thing from some table_or_other;
And get a result.
Then along came schemas.
What's a schema? It's a namespace that allows tables within a database to be grouped.
Now when you run the above you'd get something like:
ERROR: column "something" does not exist
LINE 1: select something, something_else, a_third_thing from some_table_or_other;
This is because you need to specify the schema you want to search.
How do you know what schema to search?
Well you can list the tables and Postgres will by default show a column with the schema names, e.g.:
ckan_prd=# \dt
List of relations
Schema | Name | Type | Owner
--------+-------------------------------+-------+----------
public | activity | table | ckan_prd
public | activity_detail | table | ckan_prd
public | authorization_group | table | ckan_prd
. . .
You can also list the schemas themselves e.g :
ckan_prd=# \ds
List of relations
Schema | Name | Type | Owner
--------+-----------------------------+----------+----------
public | system_info_id_seq | sequence | ckan_prd
public | system_info_revision_id_seq | sequence | ckan_prd
(2 rows)
. . .
Once you have identified the schema there are a couple of ways you can specify it, that I know of.
First you can do it in the query, by prepending the relevant schema to the table name(s)* with a dot ('.'), e.g.
select something, something_else, a_third_thing from some_schema.some_table_or_other
This may seem a little counter-intuitive as the error message above seems to indicate that postgres is havnig a problem finding the column, not the table. But no matter. I'm sure if you think about it there is a perfectly logical explanation. I've declined to think about it, so I can't tell you. Anyhoo...
The other way you can do it, if you know you're going to be working with a single schema all or most of the time is set the SCHEMA environment variable, e.g.:
set SCHEMA 'public';
Note: the variable name SCHEMA is case sensitive, the value 'public' is single quoted and the end of statement semi colon (';') is required.
That's it. Go forth and query postgres.
That's it. Go forth and query postgres.
* Note: not actually sure if you can query tables from different schemas in a single query. I assume you can but I'm not really an RDBMS man.
References:
Sunday, August 17, 2014
A little date magic
Convert A Unix Timestamp to Human Readable Localtime
Note: the version of date used here is GNU date, that is supplied with most free unices. It may also be supplied with some proprietary unices as an optional, third party or perhaps standard option. GNU date is far more powerful and featureful than most of the proprietary date commands I've experienced, so if you're on a system without GNU date, YMMV.Unix time is stored in seconds since 00:00:00 1 Jan 1970 (it may actually be 00:00:01 1 Jan 1970, not 100% sure and it doesn't make much difference for most operations).
00:00:00 1 Jan 1970 is referred to as the Unix epoch, the time unix started to exist.
This method of measuring time is unsurprisingly referred to as "Unix epoch time" or "Unix time". Less accurately (because there is more than one kind of system) "system time".
Unix Epoch Time to Human Readable System Local
To take seconds since 00:00 1 Jan 1970 (i.e. unix epoch time) and convert it to the current system local time:date -d @<seconds> since 00:00 1 Jan 1970>
System Local Time as Unix Epoch Time
To print the local system time in Unix epoch time:date +%s
UMT
[root@ckan-db .ssh]# dateMon Aug 18 12:44:39 CST 2014
[root@ckan-db .ssh]# date -u
Mon Aug 18 03:14:41 UTC 2014
[root@ckan-db .ssh]#
Labels:
date,
epoch,
epoch time,
GNU date,
system time,
unix epoch,
unix time
Subscribe to:
Posts (Atom)