Timezone doesn't change after update to Asia/Tehran in CentOS 6.6 - linux

I have changed server timezone with following commands :
cp /etc/localtime /root/old.timezone
rm /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Tehran /etc/localtime
but When I check server timezone it shows :
$ date
---------
Wed Apr 22 08:15:03 UTC 2015
which is wrong.
also /etc/localtime out put is :
TZif2UTCTZif2UTC
UTC0
How do I change server timezone?
OS : CentOS
Version : 6.6

I have a CentOS 6.6 and I did as follow
# mv localtime localtime.old
# date
Thu Apr 23 13:14:36 UTC 2015
# ln -s /usr/share/zoneinfo/Asia/Tehran /etc/localtime
# ll localtime
lrwxrwxrwx. 1 root root 31 Apr 23 17:45 localtime -> /usr/share/zoneinfo/Asia/Tehran
# date
Thu Apr 23 17:45:36 IRDT 2015
as you see it did work prefect for me, I did all these change with root user

Related

Postgresql Failed to start on linux

My PostgreSQL stopped working suddenly and I am unable to start it. (Last changes in my Linux were, I tried to install dockers).
When I run the command:
sudo service postgresql restart
OR
sudo service postgresql start
I get the error:
* Starting PostgreSQL 11 database server
* Failed to issue method call: Unit postgresql#11-main.service failed to load: No such file or directory. See system logs and 'systemctl status postgresql#11-main.service' for details.
[fail]
and
~$ sudo service postgresql status
11/main (port 5434): down
There result of systemctl status:
~ $ sudo systemctl status postgresql#11-main.service
postgresql#11-main.service
Loaded: error (Reason: No such file or directory)
Active: inactive (dead)
I have tried all the available options on SO and on other forums but neither worked for me.
What can be the issue?
EDIT:
cat /etc/os-release
Output:
NAME="Ubuntu"
VERSION="14.04.6 LTS, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04.6 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
and
ls -al /var/lib/pgsql
output:
ls: cannot access /var/lib/pgsql: No such file or directory
Then I tried
ls -al /var/lib/postgresql/
output:
total 40
drwxr-xr-x 7 postgres postgres 4096 Mar 24 13:34 .
drwxr-xr-x 90 root root 4096 Apr 6 18:36 ..
drwxr-xr-x 4 postgres postgres 4096 Apr 6 18:20 11
drwxr-xr-x 3 postgres postgres 4096 Feb 11 2016 9.3
drwxr-xr-x 3 postgres postgres 4096 Dec 3 2018 9.4
drwx------ 2 postgres postgres 4096 Jan 31 11:20 .aptitude
-rw------- 1 postgres postgres 5898 Apr 6 18:33 .bash_history
drwx------ 3 postgres postgres 4096 Feb 11 2016 .cache
-rw------- 1 postgres postgres 2180 Mar 24 13:34 .psql_history
and
yum info postgresql11-server
Error: No matching Packages to list
EDIT 2
sudo systemctl list-unit-files | grep postg et
output:
grep: et: No such file or directory
and
ls -l /var/lib/postgresql/11
output:
total 8
drwxr-xr-x 2 root root 4096 Apr 6 18:20 data
drwx------ 19 postgres postgres 4096 Apr 2 18:53 main

How can I customise an ISO image of Webconverger with a Linux shell script?

I want to write a simple shell script that downloads the latest ISO image of Webconverger and changes the boot parameters of grub in /boot/live.cfg.
So this is what I have done so far:
#!/bin/bash
# 1. Download the ISO
wget https://build.webconverger.com/latest.iso
# 2. Mount the ISO and create a development folder
sudo mkdir /mnt/webconverger
sudo mount -o loop latest.iso /mnt/webconverger
mkdir devfolder
rsync -av /mnt/webconverger/ devfolder/
sudo umount /mnt/webconverger
sudo rm -r /mnt/webconverger
# 3. Change the file in the development folder.
chmod -R 777 devfolder/
rm devfolder/boot/live.cfg
echo \
"DEFAULT de
label de
menu label Start
kernel /live/vmlinuz
append initrd=/live/initrd.img boot=live skipconfig quiet splash components=gitfs net.ifnames=0 bootfrom=removable locale=de xkb=-layout%20de homepage=https://www.google.de/" \
> devfolder/boot/live.cfg
# 4. Create a new ISO image
mkisofs -o new.iso -l devfolder
rm -r devfolder/
The generated ISO does not boot.
I asume the reasons for the problem are, that I had to run the whole script with root privileges and that I need a more complex mkisofs command.
Does anybody know how to generate a proper ISO image for Webconverger with a shell script? Or is there an alternative method for the whole process? Something like ISO Master but for the command line?
Update
I have replaced the code snippets with the actual shell script. So it is easier to test. And here is the command line output (without the wget part):
mount: /dev/loop0 is write-protected, mounting read-only
sending incremental file list
./
boot/
boot/boot.bin
boot/boot.cat
boot/live.cfg
boot/syslinux/
boot/syslinux/ldlinux.c32
boot/syslinux/libcom32.c32
boot/syslinux/libutil.c32
boot/syslinux/splash.png
boot/syslinux/syslinux.cfg
boot/syslinux/vesainfo.c32
boot/syslinux/vesamenu.c32
live/
live/initrd.img
live/vmlinuz
live/filesystem.git/
live/filesystem.git/HEAD
live/filesystem.git/config
live/filesystem.git/description
live/filesystem.git/packed-refs
live/filesystem.git/shallow
live/filesystem.git/branches/
live/filesystem.git/hooks/
live/filesystem.git/hooks/applypatch-msg.sample
live/filesystem.git/hooks/commit-msg.sample
live/filesystem.git/hooks/post-update.sample
live/filesystem.git/hooks/pre-applypatch.sample
live/filesystem.git/hooks/pre-commit.sample
live/filesystem.git/hooks/pre-push.sample
live/filesystem.git/hooks/pre-rebase.sample
live/filesystem.git/hooks/pre-receive.sample
live/filesystem.git/hooks/prepare-commit-msg.sample
live/filesystem.git/hooks/update.sample
live/filesystem.git/info/
live/filesystem.git/info/exclude
live/filesystem.git/objects/
live/filesystem.git/objects/info/
live/filesystem.git/objects/pack/
live/filesystem.git/objects/pack/pack-1aa978c13266848f4644754d1875dc90ec4bfcdb.idx
live/filesystem.git/objects/pack/pack-1aa978c13266848f4644754d1875dc90ec4bfcdb.pack
live/filesystem.git/refs/
live/filesystem.git/refs/heads/
live/filesystem.git/refs/heads/master
live/filesystem.git/refs/remotes/
live/filesystem.git/refs/remotes/origin/
live/filesystem.git/refs/remotes/origin/HEAD
live/filesystem.git/refs/tags/
live/filesystem.git/refs/tags/initial-revision
sent 598,528,659 bytes received 726 bytes 239,411,754.00 bytes/sec
total size is 598,380,033 speedup is 1.00
I: -input-charset not specified, using utf-8 (detected in locale settings)
1.71% done, estimate finish Tue Jul 10 20:12:54 2018
3.42% done, estimate finish Tue Jul 10 20:12:54 2018
5.13% done, estimate finish Tue Jul 10 20:13:13 2018
6.84% done, estimate finish Tue Jul 10 20:13:08 2018
8.55% done, estimate finish Tue Jul 10 20:13:05 2018
10.26% done, estimate finish Tue Jul 10 20:13:03 2018
11.97% done, estimate finish Tue Jul 10 20:13:02 2018
13.68% done, estimate finish Tue Jul 10 20:13:01 2018
15.39% done, estimate finish Tue Jul 10 20:13:00 2018
17.10% done, estimate finish Tue Jul 10 20:12:59 2018
18.81% done, estimate finish Tue Jul 10 20:12:59 2018
20.52% done, estimate finish Tue Jul 10 20:12:58 2018
22.23% done, estimate finish Tue Jul 10 20:12:58 2018
23.94% done, estimate finish Tue Jul 10 20:12:58 2018
25.65% done, estimate finish Tue Jul 10 20:12:57 2018
27.36% done, estimate finish Tue Jul 10 20:12:57 2018
29.07% done, estimate finish Tue Jul 10 20:12:57 2018
30.78% done, estimate finish Tue Jul 10 20:12:57 2018
32.49% done, estimate finish Tue Jul 10 20:12:57 2018
34.20% done, estimate finish Tue Jul 10 20:12:56 2018
35.91% done, estimate finish Tue Jul 10 20:12:56 2018
37.62% done, estimate finish Tue Jul 10 20:12:56 2018
39.33% done, estimate finish Tue Jul 10 20:12:56 2018
41.04% done, estimate finish Tue Jul 10 20:12:56 2018
42.75% done, estimate finish Tue Jul 10 20:12:56 2018
44.46% done, estimate finish Tue Jul 10 20:12:56 2018
46.17% done, estimate finish Tue Jul 10 20:12:56 2018
47.88% done, estimate finish Tue Jul 10 20:12:56 2018
49.59% done, estimate finish Tue Jul 10 20:12:56 2018
51.30% done, estimate finish Tue Jul 10 20:12:55 2018
53.02% done, estimate finish Tue Jul 10 20:12:55 2018
54.72% done, estimate finish Tue Jul 10 20:12:55 2018
56.44% done, estimate finish Tue Jul 10 20:12:55 2018
58.14% done, estimate finish Tue Jul 10 20:12:55 2018
59.86% done, estimate finish Tue Jul 10 20:12:55 2018
61.56% done, estimate finish Tue Jul 10 20:12:55 2018
63.28% done, estimate finish Tue Jul 10 20:12:55 2018
64.98% done, estimate finish Tue Jul 10 20:12:55 2018
66.70% done, estimate finish Tue Jul 10 20:12:55 2018
68.40% done, estimate finish Tue Jul 10 20:12:55 2018
70.12% done, estimate finish Tue Jul 10 20:12:55 2018
71.82% done, estimate finish Tue Jul 10 20:12:55 2018
73.54% done, estimate finish Tue Jul 10 20:12:55 2018
75.24% done, estimate finish Tue Jul 10 20:12:55 2018
76.96% done, estimate finish Tue Jul 10 20:12:55 2018
78.66% done, estimate finish Tue Jul 10 20:12:55 2018
80.38% done, estimate finish Tue Jul 10 20:12:55 2018
82.08% done, estimate finish Tue Jul 10 20:12:55 2018
83.80% done, estimate finish Tue Jul 10 20:12:55 2018
85.50% done, estimate finish Tue Jul 10 20:12:55 2018
87.22% done, estimate finish Tue Jul 10 20:12:55 2018
88.92% done, estimate finish Tue Jul 10 20:12:55 2018
90.64% done, estimate finish Tue Jul 10 20:12:55 2018
92.34% done, estimate finish Tue Jul 10 20:12:55 2018
94.06% done, estimate finish Tue Jul 10 20:12:55 2018
95.76% done, estimate finish Tue Jul 10 20:12:55 2018
97.48% done, estimate finish Tue Jul 10 20:12:55 2018
99.18% done, estimate finish Tue Jul 10 20:12:55 2018
Total translation table size: 0
Total rockridge attributes bytes: 0
Total directory bytes: 30720
Path table size(bytes): 222
Max brk space used 2b000
292387 extents written (571 MB)
And this what I get in VirtualBox:
Click here!
So the full answer to the question is:
#!/bin/bash
# 1. Download the ISO
wget https://build.webconverger.com/latest.iso
# 2. Mount the ISO and create a development folder
sudo mkdir /mnt/webconverger
sudo mount -o loop latest.iso /mnt/webconverger
mkdir devfolder
rsync -av /mnt/webconverger/ devfolder/
sudo umount /mnt/webconverger
sudo rm -r /mnt/webconverger
# 3. Change the file in the development folder.
echo \
"DEFAULT de
label de
menu label Start
kernel /live/vmlinuz
append initrd=/live/initrd.img boot=live skipconfig quiet splash components=gitfs net.ifnames=0 bootfrom=removable locale=de xkb=-layout%20de homepage=https://duckduckgo.com nobrand" \
| sudo tee devfolder/boot/live.cfg
# 4. Create a new ISO image
sudo mkisofs -r -J -l -V "Webconverger" -b boot/boot.bin -c boot/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o new.iso devfolder
sudo isohybrid new.iso
sudo rm -r devfolder/
For some reason dd did not work for Webconverger images. Even the with the untouched latest.iso it was not possible to create a bootable USB flash drive. So I used Win32DiskImager.
What you want to do is to generate an El Torito bootable CD with an MBR in its first bytes.
mkisofs(8) needs some special options to create an "El Torito" bootable CD:
mkisofs -r -J -l -V "Webconverger" -b boot/boot.bin -c boot/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o new.iso devfolder
Explaination:
-r -J: Enable Joliet and Rock Ridge meta data.
-l: Allow long filenames.
-V: Set volume ID. Optional.
-b: Specify the "El Torito" boot image.
-c: Specify the "El Torito" boot catalog.
-no-emul-boot: Specify that this is an "El Torito" bootable CD.
-boot-load-size: number of 512 bytes sector to load (4 is what usually works)
-boot-info-table: modify the original boot image appending the Boot Info Table
Then, if you want to be able to just dd the file on a USB drive you will need to write an MBR onto the ISO:
isohybrid new.iso

Monitor the rate of log file writes matching a pattern

I have a timestamped log file that I am watching. Every so often the log writes a message, "OK"
How could I capture the number of "OK"s written per second? E.g. output like
10.5 OK/sec
9 OK/sec
20 OK/sec
The log is pretty big, its not practical to do a grep on the entire file. I started with
tail -f my.log | grep OK
which is helpful but doesn't quite get me the rate.
Thanks!
First solution below is great (and other is good too), I altered it a bit and this is what I came up with
tail -f my.log | perl -lne 'if(/(\d+:\d+:\d+).*OK/) { print $1; }'| uniq -c
When your log is in form like:
Wed Jul 10 22:44:00 CEST 2013 OK
Wed Jul 10 22:44:00 CEST 2013 OK
Wed Jul 10 22:44:00 CEST 2013 OK
Wed Jul 10 22:44:00 CEST 2013 OK
Wed Jul 10 22:44:01 CEST 2013 OK
Wed Jul 10 22:44:01 CEST 2013 OK
Wed Jul 10 22:44:01 CEST 2013 OK
Wed Jul 10 22:44:01 CEST 2013 OK
Wed Jul 10 22:44:01 CEST 2013 OK
Wed Jul 10 22:44:01 CEST 2013 OK
Wed Jul 10 22:44:01 CEST 2013 OK
Wed Jul 10 22:44:01 CEST 2013 OK
so, in form timestamp OK, you can try the simple:
tail -f logfile | uniq -c
and you will get the next result:
4 Wed Jul 10 22:44:00 CEST 2013 OK
8 Wed Jul 10 22:44:01 CEST 2013 OK
^
+---- number of OK in the same timestamp
Here's a quick script to do it:
#! /bin/bash
log="/var/log/messages"
seconds="1"
filter="OK"
while true; do
echo "$(timeout $seconds tail -n0 -f $log|grep $filter|wc -l) OK/sec"
done
There's a bit of a race condition where it might lose one or two lines during the loop, but it is unlikely. Also, not every Linux distro has timeout installed by default, so you might want to check.

How to get the start time of a long-running Linux process?

Is it possible to get the start time of an old running process? It seems that ps will report the date (not the time) if it wasn't started today, and only the year if it wasn't started this year. Is the precision lost forever for old processes?
You can specify a formatter and use lstart, like this command:
ps -eo pid,lstart,cmd
The above command will output all processes, with formatters to get PID, command run, and date+time started.
Example (from Debian/Jessie command line)
$ ps -eo pid,lstart,cmd
PID CMD STARTED
1 Tue Jun 7 01:29:38 2016 /sbin/init
2 Tue Jun 7 01:29:38 2016 [kthreadd]
3 Tue Jun 7 01:29:38 2016 [ksoftirqd/0]
5 Tue Jun 7 01:29:38 2016 [kworker/0:0H]
7 Tue Jun 7 01:29:38 2016 [rcu_sched]
8 Tue Jun 7 01:29:38 2016 [rcu_bh]
9 Tue Jun 7 01:29:38 2016 [migration/0]
10 Tue Jun 7 01:29:38 2016 [kdevtmpfs]
11 Tue Jun 7 01:29:38 2016 [netns]
277 Tue Jun 7 01:29:38 2016 [writeback]
279 Tue Jun 7 01:29:38 2016 [crypto]
...
You can read ps's manpage or check Opengroup's page for the other formatters.
The ps command (at least the procps version used by many Linux distributions) has a number of format fields that relate to the process start time, including lstart which always gives the full date and time the process started:
# ps -p 1 -wo pid,lstart,cmd
PID STARTED CMD
1 Mon Dec 23 00:31:43 2013 /sbin/init
# ps -p 1 -p $$ -wo user,pid,%cpu,%mem,vsz,rss,tty,stat,lstart,cmd
USER PID %CPU %MEM VSZ RSS TT STAT STARTED CMD
root 1 0.0 0.1 2800 1152 ? Ss Mon Dec 23 00:31:44 2013 /sbin/init
root 5151 0.3 0.1 4732 1980 pts/2 S Sat Mar 8 16:50:47 2014 bash
For a discussion of how the information is published in the /proc filesystem, see
https://unix.stackexchange.com/questions/7870/how-to-check-how-long-a-process-has-been-running
(In my experience under Linux, the time stamp on the /proc/ directories seem to be related to a moment when the virtual directory was recently accessed rather than the start time of the processes:
# date; ls -ld /proc/1 /proc/$$
Sat Mar 8 17:14:21 EST 2014
dr-xr-xr-x 7 root root 0 2014-03-08 16:50 /proc/1
dr-xr-xr-x 7 root root 0 2014-03-08 16:51 /proc/5151
Note that in this case I ran a "ps -p 1" command at about 16:50, then spawned a new bash shell, then ran the "ps -p 1 -p $$" command within that shell shortly afterward....)
As a follow-up to Adam Matan's answer, the /proc/<pid> directory's time stamp as such is not necessarily directly useful, but you can use
awk -v RS=')' 'END{print $20}' /proc/12345/stat
to get the start time in clock ticks since system boot.1
This is a slightly tricky unit to use; see also convert jiffies to seconds for details.
awk -v ticks="$(getconf CLK_TCK)" 'NR==1 { now=$1; next }
END { printf "%9.0f\n", now - ($20/ticks) }' /proc/uptime RS=')' /proc/12345/stat
This should give you seconds, which you can pass to strftime() to get a (human-readable, or otherwise) timestamp.
awk -v ticks="$(getconf CLK_TCK)" 'NR==1 { now=$1; next }
END { print strftime("%c", systime() - (now-($20/ticks))) }' /proc/uptime RS=')' /proc/12345/stat
Updated with some fixes from Stephane Chazelas in the comments; thanks as always!
If you only have Mawk, maybe try
awk -v ticks="$(getconf CLK_TCK)" -v epoch="$(date +%s)" '
NR==1 { now=$1; next }
END { printf "%9.0f\n", epoch - (now-($20/ticks)) }' /proc/uptime RS=')' /proc/12345/stat |
xargs -i date -d #{}
1 man proc; search for starttime.
ls -ltrh /proc | grep YOUR-PID-HERE
For example, my Google Chrome's PID is 11583:
ls -l /proc | grep 11583
dr-xr-xr-x 7 adam adam 0 2011-04-20 16:34 11583
$ ps -p 182454 -o lstart=
Mon Oct 18 17:26:44 2021
But can I get the answer in epoch seconds?
ps -eo pid,cmd,lstart | grep YOUR-PID-HERE
ps -eo pid,etime,cmd|sort -n -k2
use the command ls -ld /proc/process_id where process_id can be find using top command

Real-time display of `date` changes on Linux

On an embedded Linux device that does not present /dev/rtc*, how can I set off a console window writing the value of the Real-Time Clock to the console, on the tick, every time it changes?
Results would be like:
$ **someCmd**
Mon Mar 14 16:43:22 UTC 2011
Mon Mar 14 16:43:23 UTC 2011
Mon Mar 14 16:43:24 UTC 2011
Mon Mar 14 16:43:25 UTC 2011
Mon Mar 14 16:43:26 UTC 2011
etc.
The device is armv5tejl running BusyBox v1.13.3.
Use the watch commad, try this is:
watch -n 1 date
I don't know how much the BusyBox shell supports, but in sh you could do something like this:
{ while true ; do date ; sleep 0.1 ; done } | uniq

Resources