Hello I would like to ask if it can not connect automatically to the site at 09:00 AM using wget
It would be nice if I did not have to open the page manually for points each day.
Thanks
you can schedule an cron job
then use below commands
$ crontab -e
$ 00 09 * * * /path/to/script.sh
more description on
here
if you are on windows then you can use task scheduler inbuilt given in windows
I want to restart my Raspberry PI once a week. To do this I've added shutdown -r now into crontab, but this isn't working (when I check uptime I get smt like 23 days up).
Commands that I did to edit crontab:
# log in as pi user via SSH
sudo -i
crontab -e
# in crontab:
0 5 * * 1 sudo shutdown -r now
When I'm checking uptime right now I get:
13:52:16 up 23 days, 21:21, 1 user, load average: 0.87, 0.92, 0.95
PS
I'm running RaspBMC
Cron jobs are per default disabled in RaspBMC. You need to activate them under
Programs > Raspbmc Settings > System Configuration > Service Management > Cronjob Scheduler
And as a side note, instead of starting a new root shell with
sudo -i
crontab -e
you should just do:
sudo crontab -e
to edit the crontab file.
How to Correct Timezone
Last time, I figured out how to adjust a system clock in vagrant server. However, when I halt the vagrant and start it again, the system clock is always 9 hours late. I can adjust by using ntp command manually, but I'd like to know how to adjust the system clock automatically.
I have tried the below, but it still doesn't work. Are there any suggestions?
How to sync time on host wake-up within VirtualBox?
The method I use and it should not be provider specific is to add the following in my Vagrantfile
config.vm.provision :shell, :inline => "sudo rm /etc/localtime && sudo ln -s /usr/share/zoneinfo/Europe/Paris /etc/localtime", run: "always"
you would need to replace '/Europe/Paris' with the timezone you want to set
The simplest way is to set the timezone automatically is to use the vagrant-timezone plugin.
Install it once with:
vagrant plugin install vagrant-timezone
After that, add the below to your Vagrantfile:
if Vagrant.has_plugin?("vagrant-timezone")
config.timezone.value = "UTC"
end
You may replace "UTC" with any of the tz values listed here.
For example: "Asia/Kolkata".
Or you can use your host's timezone with this entry in your Vagrantfile:
if Vagrant.has_plugin?("vagrant-timezone")
config.timezone.value = :host
end
Accepted answer is not robust enough, as it does not account for people who travel between timezones, and requires end users to modify Vagrantfile instead of just doing vagrant up.
Building up on Scott P.'s answer, here's a better more flexible solution that matches VM timezone to host's tz automatically. There's a typo/mistake in his snippet's Etc/GMT time zone selection, as per POSIX GMT+7 sets clock 7 hours behind (see Wiki explanation), hence we need to swap offsets:
Vagrant.configure("2") do |config|
require 'time'
offset = ((Time.zone_offset(Time.now.zone) / 60) / 60)
timezone_suffix = offset >= 0 ? "-#{offset.to_s}" : "+#{offset.to_s}"
timezone = 'Etc/GMT' + timezone_suffix
config.vm.provision :shell, :inline => "sudo rm /etc/localtime && sudo ln -s /usr/share/zoneinfo/" + timezone + " /etc/localtime", run: "always"
end
I got:
[vagrant#ansiblecontrol ~]$ date -s \"$(curl -I google.com 2>&1 | grep Date: | cut -d' ' -f3-6)Z\"
date: extra operand ‘2018’
Try 'date --help' for more information.
This works for me:
sudo date -s "$(curl -I google.com 2>&1 | grep Date: | cut -d' ' -f3-6)Z"
Sun Apr 1 16:36:59 CEST 2018
So removed the "\" escape character.
A slightly improved version that auto-detects timezone:
The auto-detect portion came from here.
Vagrant.configure("2") do |config|
require 'time'
offset = ((Time.zone_offset(Time.now.zone) / 60) / 60)
timezone_suffix = offset >= 0 ? "+#{offset.to_s}" : "#{offset.to_s}"
timezone = 'Etc/GMT' + timezone_suffix
config.vm.provision :shell, :inline => "sudo rm /etc/localtime && sudo ln -s /usr/share/zoneinfo/" + timezone + " /etc/localtime", run: "always"
end
My Vagrant Guest OS time was out of sync by 7 days. The above methods did not work for me, since Guest additions and ntp were not installed in my Guest machine.
I finally solved the issue by using the hack from
https://askubuntu.com/a/683136/119371
cfg.vm.provision "shell", inline: "date -s \"$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z\"", run: "always", privileged: true, upload_path: "/home/vagrant/tmp/vagrant-shell"
The above method does not sync the Guest OS time with your host machine or any NTP server. It sends an HTTP request to google.com and updates the system time with the time in the HTTP response header field.
Hence, depending on your internet connection speed and latency, the updated time could be off by several milliseconds to a few seconds (usually < 100ms). But it shouldn't matter for most cases.
Following is the curl version, if you don't want to use wget for any reason
cfg.vm.provision "shell", inline: "date -s \"$(curl -I google.com 2>&1 | grep Date: | cut -d' ' -f3-6)Z\""
#Benny K and #Scott P.'s solution giving me the negative value of a timezone, like in #rubo77's case. Worth to note that my host OS is Windows. If timedatectl is present on your guests (like Debian 9+), this is what I used to change timezone settings:
config.vm.provision "shell",
inline: "timedatectl set-timezone Europe/Budapest",
run: "always"
This one returns the expected timezone, not the negative value:
# before timedatectl
vagrant#master:~$ timedatectl
Local time: Fri 2020-07-03 11:52:31 -02
Universal time: Fri 2020-07-03 13:52:31 UTC
RTC time: Fri 2020-07-03 13:52:31
Time zone: Etc/GMT+2 (-02, -0200)
System clock synchronized: no
NTP service: inactive
RTC in local TZ: no
# after timedatectl
vagrant#master:~$ timedatectl
Local time: Fri 2020-07-03 15:53:24 CEST
Universal time: Fri 2020-07-03 13:53:24 UTC
RTC time: Fri 2020-07-03 13:53:24
Time zone: Europe/Budapest (CEST, +0200)
System clock synchronized: no
NTP service: inactive
RTC in local TZ: no
Based on #Benny K.'s answer (https://stackoverflow.com/a/46778032/3194807), with the daylight saving time taken into account:
require "time"
offset = ((Time.zone_offset(Time.now.zone) / 60) / 60) + (Time.now.dst? ? 1 : 0)
timezone_suffix = offset >= 0 ? "-#{offset.to_s}" : "+#{offset.to_s}"
timezone = 'Etc/GMT' + timezone_suffix
tzShellProvision = <<_SHELL_
ln -fs /usr/share/zoneinfo/#{timezone} /etc/localtime
dpkg-reconfigure -f noninteractive tzdata
_SHELL_
default.vm.provision :shell, inline: tzShellProvision, run: "always"
The way is to set the timezone automatically same like host using
the vagrant-timezone plugin.
Install the vagrant-timezone plugin with
vagrant plugin install vagrant-timezone
After that, add the below to your Vagrantfile
config.timezone.value = :host
Note that this functionality has only been tested with an OS X host and Linux guest.
I use postgresql on Debian.
The postgresql service can not start after I edit the config file:
#data_directory = '/var/lib/postgresql/9.4/main' # use data in another directory
data_directory = '/opt/data/postgresql/data'
(yeah,I just use custom directory instead of the default data_directory)
I find the log in /var/log/syslog
Sep 14 10:22:17 thinkserver-ckd postgresql#9.4-main[11324]: Error: could not exec /usr/lib/postgresql/9.4/bin/pg_ctl /usr/lib/postgresql/9.4/bin/pg_ctl start -D /opt/data/postgresql/data -l /var/log/postgresql/postgresql-9.4-main.log -s -o -c config_file="/etc/postgresql/9.4/main/postgresql.conf" :
Sep 14 10:22:17 thinkserver-ckd systemd[1]: postgresql#9.4-main.service: control process exited, code=exited status=1
Sep 14 10:22:17 thinkserver-ckd systemd[1]: Failed to start PostgreSQL Cluster 9.4-main.
Sep 14 10:22:17 thinkserver-ckd systemd[1]: Unit postgresql#9.4-main.service entered failed state.
And nothing in /var/log/postgresql/postgresql-9.4-main.log
Thanks.
I finally got this answer:
What this error means in PostgreSQL?
#langton 's answer.
He said that
you should run pg_upgradecluster or similar, or just create a new cluster with pg_createcluster (these commands are for debian systems - you didn't specify your OS)
So I executed the command:
pg_createcluster -d /opt/data/postgresql/data -l /opt/data/postgresql/log 9.4 ckd
And then :
service postgresql restart
it started!
If downtime is allowed and you already have databases with data in the old cluster location you only need to physically copy the data to the new location.
This is a more or less common operation if you partition is out of space.
# Check that current data directory is the same that
# the one in the postgresql.conf config file
OLD_DATA_DIR=$(sudo -u postgres psql --no-psqlrc --no-align --tuples-only --quiet -c "SHOW data_directory;")
echo "${OLD_DATA_DIR}"
CONFIG_FILE=$(sudo -u postgres psql --no-psqlrc --no-align --tuples-only --quiet -c "SHOW config_file;")
echo "${CONFIG_FILE}"
# Stop PostgreSLQ
systemctl stop postgresql
# Change the data directory in the config
# Better to do it with an editor, instead of sed
NEW_DATA_DIR='/opt/data/postgresql/data'
sed -i "s%data_directory = '${OLD_DATA_DIR}'%data_directory = '${NEW_DATA_DIR}'%" "${CONFIG_FILE}"
# Move/Copy the data for example using rsync
rsync -av --dry-run "${OLD_DATA_DIR}" "${NEW_DATA_DIR}"
# Take care with the classical issues of rsync and end backslashes
rsync -av "${OLD_DATA_DIR}" "${NEW_DATA_DIR}"
# Rename the old dir, just to avoid missunderstandings and set
# check the permissions on the new one
# Start postgres
systemctl start postgresql
# Check that everything goes well and eventually drop the old data
# Make sure that the logs and everything else is where you want.
I have Linux Centos 6.5, and I have tried different backup scripts, but I have failed each time. I only have a small amount of experience with Linux, I've only used it to set up a server etc. so I don't know how to do proper backups. I have a 100GB FTP server connected to my Linux server that I can use for backups.
I need a script that takes a weekly backup and also a daily incremental backup. I only need to backup certain directories, e.g. /home, /etc and so on. It should also automatically execute every week/day and take a backup and put that backup on the FTP server.
Is there anyone who has a proper and working script for this?
Assuming that you have installed Centos, you obviously have crond tool. Put your routines into the cron, and it will execute any script at the specified time:
su #login as root
crontab -e
This will run the FTP upload every day at hh:mm:
mm hh * * * curl --upload-file testfile.zip ftp://user:password#ftp.domain.com/
But i find it more useful to use direct filesystem access for creating backups (you need to configure ssh public key access before):
mm hh * * day_of_week_number rsync -avh -e --updates --delete /source remote.host:/dest
Adding below intro to the crontab will help to take weekly backup of Linux partitions.
mm hh * * dow rsync -avh -e --updates --delete /source /destination