How to change the date and time in linode server - linode

I want to change the date and time in linode server which should give me my preferred time and date.
sudo date --set = "2018-08-06 11:05:00"
sudo date --set = "2018-08-06 11:05:00"
The above command I'm giving but once I gave command like date it showing the current time and date not my preferred date and time

access terminal and type following command;
sudo dpkg-reconfigure tzdata
time zone info is saved in /etc/timezone
which can be edited
$ echo "Australia/Adelaide" | sudo tee /etc/timezone
Asutralia/Adelaide
$sudo dpkg-reconfigure --frontend noninteractive tzdata
then proceed with the time configuration of your time zone.
you will see clock and time zone here in terminal as well.
thanks,
Syeda

Related

How to auto run commands when log on to Windows Subsystem for Linux

I have a Ubuntu 20.04 running within WSL 2 on a Windows 10 computer.
Every time I login to Ubuntu, I had to manually execute these four line by pasting it one by one in the Windows 10 Terminal.
sudo apt-get update && sudo apt-get install -yqq daemonize dbus-user-session fontconfig
sudo daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target
exec sudo nsenter -t $(pidof systemd) -a su - $LOGNAME
sudo /etc/init.d/xrdp start
May I know if there is a way to skip this manual process?
You can use .bashrc file to execute commands whenever you open the terminal. It should be located at $HOME directory.
cd $HOME
nano .bashrc
place your commands at the end of the file, press ctl+x then y to save.

Adding newuser in docker container with sudo privileges

Im trying to build a docker file and one of the reqt is to create a user with sudo permissions.
Here is the bash script
# quietly add a user without password
adduser --quiet --disabled-password --shell /bin/bash --home /home/newuser --gecos "testuser" newuser
# set password
echo "testuser:testuser" | sudo chpasswd
and the docker compose file.
FROM ros
RUN apt-get update
RUN apt-get install -y sudo
ADD run.sh /usr/local/bin/run.sh
RUN chmod +x /usr/local/bin/run.sh
CMD ["/usr/local/bin/run.sh"]
When I run this build I get the following error.
chpasswd: (user testuser) pam_chauthtok() failed, error:
Authentication token manipulation error
chpasswd: (line 1, user testuser) password not changed
I think you're misinterpreting the requirements. Creating an user with sudo permissions is different from creating an user with the sudo command.
Depending on the distribution, an user may run sudo if it belongs to the wheel or sudo group (the latter is the case with Ubuntu, which is the base image used by ros).
I strongly suggest that you use the useradd command instead of adduser. The latter is different in Debian & RedHat based distributions, unlike the former which is the same across Linux distributions and even *BSD if you don't use the long options. Also, the former lets you specify the supplementary groups in the command line (-G option).
useradd -m -s /bin/bash -G sudo newuser
If you use the -p option you could also supply the password in encrypted form (the term in the manpage should be hashed form) without the need to use chpasswd later. Use the output of mkpasswd -m sha-512. (The mkpasswd command is present in the whois package). If you're going to use chpass, use the -e option to supply the password in encrypted form. Never use plaintext.

OS X Shell Script to run ntpdate

turns out I'm really bad at shell scripts...
I'm trying to make a script that will run;
ntpdate -u time.apple.com
So I created this script;
#!/bin/sh
ntpdate -u time.apple.com
I've chmod +X the script but it won't execute when I call
sudo ./timefix.sh
sudo: ./timefix.sh: command not found
If I just call ./timefix.sh I get;
-bash: ./timefix.sh: Permission denied
ntpdate requires sudo privileges to run.
My final goal is to package this up into an app with Automator so that it runs every boot. I have a handful of Macs in this office that are having internal clock issues. This is meant to be my dirty work around until I can get time to strip them back and replace the RTC batteries.
Can anyone help me fix my script please?
just change +X to a lower case +x.
chmod +x ./timefix.sh

How can I run one line of bash shell script as a specific user

I have a script I run manually (let's say) mylogin. But there's one line that needs to run as user postgres.
What is a good way to do that?
It's ok if I get a password prompt. I just need it to work somehow.
Here's what I have so far...
~/reload_test_data.sh
#!/bin/bash
# Here's the part that needs to run as user `postgres`...
sudo su postgres
export PGDATA=/Library/PostgreSQL/9.4/data && pg_ctl -m fast restart
# And here we should go back to `mylogin`...
cd ~/projects/my_project
echo 'Dropping database'
bundle exec rake db:drop
# More stuff etc...
I'm using Mac OS 10.12.1.
One of the arguments for sudo is the command so you can do something like:
sudo -u <user> bash -c "command_1; command_2; etc"
where -u <user> change to your target user

How could I run a shell script with delay

I basically want to run a script which is a server but with 10 second delay, it is because I need some stuff to run before this script.
The server is located in the folder /etc/init.d but basically to make it work I go to that path using the command line and I have to restart the server typing:
sudo ./znodejs.sh stop
And then I start the server again:
sudo ./znodejs.sh start
I would like to know if there is any way to run those commands with a delay.
In order to make a script run on startup first make it executable:
$ sudo chmod 755 /etc/init.d/znodejs.sh
Then you can register the script to be run at startup:
$ sudo update-rc.d znodejs.sh defaults
(Edit)
original answer:
the sleep command sill pause for a given number of seconds:
sudo ./znodejs.sh stop
sleep 10
sudo ./znodejs.sh start
The standard unix command for sleeping is called
sleep
to wait a second, use
sleep 1

Resources