Archive

Articles taggués ‘commands’

How To SSH Run Multiple Command On Remote Machine And Exit Safely

23/04/2024 Aucun commentaire

Source: nixCraft

I have a backup sync program on local server. I have an ssh password less login set up, and I can run commands on an external server in bash script doing:

ssh root@server2 "sync; sync; /sbin/shutdown -h now"

How do I run multiple commands in bash on a remote Unix or Linux server? What is the best Way to SSH in and Run various unix commands in bash?

There are various ways to run multiple commands on a remote Unix server. The syntax is as follows:

Simple bash syntax to run multiple commands on remote machine

Simply run command2 if command1 successful on a remote host called foo
$ ssh bar@foo "command1 && command2"
Run date and hostname commands:
$ ssh user@host "date && hostname"
You can run sudo command as follows on a remote box called server1.cyberciti.biz:
$ ssh -t vivek@server1.dbsysnet.com "sudo /sbin/shutdown -h now"
And, finally:
$ ssh root@server1.dbsysnet.com "sync && sync && /sbin/shutdown -h now"

Lire la suite…

Categories: Système Tags: , ,

How to Set Locales (i18n) On a Linux or Unix

23/04/2024 Comments off

Source: nixCraft

What is a « locale » on a Linux operating system? How do I set or get locals (i18n) values on a Linux operating system?

Locales defines language and country specific setting for your programs and shell session. You can use locales to see date, time, number, currency and other values formatted as per your country or language on a Linux or Unix-like system.

To set system’s locale you need use shell variable. For example, LANG variable can be used to set en_US (English US) language.

How do I show current locale settings on a Linux or Unix?

The syntax is:

locale
locale name
locale [options] name

Examples

Simply type the following command:

 $ locale 

show-current-locale-command

Lire la suite…

Categories: Système Tags: ,

How to Backup Linux? 15 rsync Command Examples

20/04/2024 Aucun commentaire

Source: TheGeekStuff

rsync-commandrsync stands for Remote SYNC.

rsync is used to perform the backup operation in UNIX / Linux.

rsync utility is used to synchronize the files and directories from one location to another in an effective way. Backup location could be on local server or on remote server.

Important features of rsync

  • Speed: First time, rsync replicates the whole content between the source and destination directories. Next time, rsync transfers only the changed blocks or bytes to the destination location, which makes the transfer really fast.
  • Security: rsync allows encryption of data using ssh protocol during transfer.
  • Less Bandwidth: rsync uses compression and decompression of data block by block at the sending and receiving end respectively. So the bandwidth used by rsync will be always less compared to other file transfer protocols.
  • Privileges: No special privileges are required to install and execute rsync

Syntax

$ rsync options source destination

Source and destination could be either local or remote. In case of remote, specify the login name, remote server name and location.
Lire la suite…

Categories: Système Tags: , , , ,

Rsync (Remote Sync): 10 Practical Examples of Rsync Command in Linux

18/04/2024 Aucun commentaire

Source: tecmint.com (Tarunika Shrivastava)

Rsync (Remote Sync) is a most commonly used command for copying and synchronizing files and directories remotely as well as locally in Linux/Unix systems. With the help of rsync command you can copy and synchronize your data remotely and locally across directories, across disks and networks, perform data backups and mirroring between two Linux machines.

This article explains 10 basic and advanced usage of the rsync command to transfer your files remotely and locally in Linux based machines. You don’t need to be root user to run rsync command.

Some advantages and features of Rsync command
  1. It efficiently copies and sync files to or from a remote system.
  2. Supports copying links, devices, owners, groups and permissions.
  3. It’s faster than scp (Secure Copy) because rsync uses remote-update protocol which allows to transfer just the differences between two sets of files. First time, it copies the whole content of a file or a directory from source to destination but from next time, it copies only the changed blocks and bytes to the destination.
  4. Rsync consumes less bandwidth as it uses compression and decompression method while sending and receiving data both ends.
Basic syntax of rsync command
# rsync options source destination

Lire la suite…

Categories: Système Tags: , ,

compgen: An Awesome Command To List All Linux Commands

16/04/2024 Aucun commentaire

Source: nixCraft

Ever want to list all the Linux commands (including bash shell aliases and functions) you could run on the server / workstation? Look now further. Try compgen command.

compgen is bash built-in command and it will show all available commands, aliases, and functions for you. The syntax is:

compgen option

compgen command examples

To list all the commands available to you, enter:

 
compgen -c

Sample outputs:

ls
if
then
else
elif
fi
....
mahjongg
sol
gtali
sl-h
gnobots2
gnotravex
iagno
fortune
gnect
gnome-sudoku
LS
glchess
gnuchess
gnuchessx

You can search or count the commands:

compgen -c | grep find
compgen -c | wc -l
echo "$USER user can run $(compgen -c | wc -l) commands on $HOSTNAME."

Lire la suite…

Categories: Système Tags: ,