Difference between revisions of "Linux hints"

From Klaus' wiki
Jump to: navigation, search
Line 39: Line 39:
  
 
where <remote-system> is either the IP address or its hostname including domain as in bren.hih.au.dk - if using a different username than the one you're logged in with on current system use <username>@<remote-system>
 
where <remote-system> is either the IP address or its hostname including domain as in bren.hih.au.dk - if using a different username than the one you're logged in with on current system use <username>@<remote-system>
 +
 +
== Using ssh extensively ==
 +
 +
Thanx to [http://ultra.ap.krakow.pl/~bar/DOC/ssh_backup.html this page] it is easy to collect useful examples of extensive usage of ssh.
 +
 +
Here are examples of copying from local to remote and the other way around.
 +
 +
PUSH:
 +
<source lang="bash">
 +
tar cvf - . | gzip -c -1 | ssh user@host cat ">" remotefile.gz
 +
ssh target_address cat <localfile ">" remotefile
 +
ssh target_address cat <localfile - ">" remotefile
 +
cat localfile | ssh target_address cat ">" remotefile
 +
cat localfile | ssh target_address cat - ">" remotefile
 +
dd if=localfile | ssh target_address dd of=remotefile
 +
ssh target_address cat <localfile "|" dd of=remotefile
 +
ssh target_address cat - <localfile "|" dd of=remotefile
 +
( cd SOURCEDIR && tar cf - . ) | ssh target_address "(cd DESTDIR && tar xvpf - )"
 +
( cd SOURCEDIR && tar cvf - . ) | ssh target_address "(cd DESTDIR && cat - > remotefile.tar )"
 +
( cd SOURCEDIR && tar czvf - . ) | ssh target_address "(cd DESTDIR && cat - > remotefile.tgz )"
 +
( cd SOURCEDIR && tar cvf - . | gzip -1 -) | ssh target_address "(cd DESTDIR && cat - > remotefile.tgz )"
 +
ssh target_address "( nc -l -p 9210 > remotefile & )" && cat source-file | gzip -1 - | nc target_address 9210
 +
cat localfile | gzip -1 - | ssh target_address cat ">" remotefile.gz
 +
</source>
 +
 +
PULL:
 +
<source lang="bash">
 +
ssh target_address cat remotefile > localfile
 +
ssh target_address dd if=remotefile | dd of=localfile
 +
ssh target_address cat "<" remotefile >localfile
 +
ssh target_address cat "<" remotefile.gz | gunzip >localfile
 +
</source>
 +
 +
COMPARE:
 +
<source lang="bash">
 +
###This one uses CPU cycles on the remote server to compare the files:
 +
ssh target_address cat remotefile | diff - localfile
 +
cat localfile | ssh target_address diff - remotefile
 +
###This one uses CPU cycles on the local server to compare the files:
 +
ssh target_address cat <localfile "|" diff - remotefile
 +
</source>
 +
 +
Push: Push local file to remote server.
 +
 +
Pull: Pull remote file from remote server to local machine.
  
 
== NX ==
 
== NX ==

Revision as of 12:34, 4 July 2010

Assorted hints, that makes the life easier in the daily life with Linux. Most of the hints are noted here in order to remember the exact syntax of the construct.

Create a file remotely

If you need to let output from one command locally be the input to a file on a remote system issue this command:

<local command>|ssh <remote username>@<remote host> "cat > <remotefilename>"

an example:

xmodmap -pke|ssh -p 2222 klausk@bren.hih.au.dk "cat > .Xmodmap"

the output (on stdout) will be sent to bren using klausk's login and send the result into the file .Xmodmap

Comparing two files

In general comparing two files can be done like this:

diff <firstfile> <secondfile>

or using vim

vim -d <firstfile> <secondfile>

To compare two files of which one resides on another system issue this command:

vim -d <firstfile> scp://<remote-system>//<path-to-file>/<secondfile>

To compare two files both resident on different systems issue this command:

vim -d scp://<first-remote-system>//<path-to-file>/<firstfile> scp://<second_remote-system>//<path-to-file>/<secondfile>

where <remote-system> is either the IP address or its hostname including domain as in bren.hih.au.dk - if using a different username than the one you're logged in with on current system use <username>@<remote-system>

Using ssh extensively

Thanx to this page it is easy to collect useful examples of extensive usage of ssh.

Here are examples of copying from local to remote and the other way around.

PUSH:

tar cvf - . | gzip -c -1 | ssh user@host cat ">" remotefile.gz
ssh target_address cat <localfile ">" remotefile
ssh target_address cat <localfile - ">" remotefile
cat localfile | ssh target_address cat ">" remotefile
cat localfile | ssh target_address cat - ">" remotefile
dd if=localfile | ssh target_address dd of=remotefile
ssh target_address cat <localfile "|" dd of=remotefile
ssh target_address cat - <localfile "|" dd of=remotefile
( cd SOURCEDIR && tar cf - . ) | ssh target_address "(cd DESTDIR && tar xvpf - )"
( cd SOURCEDIR && tar cvf - . ) | ssh target_address "(cd DESTDIR && cat - > remotefile.tar )"
( cd SOURCEDIR && tar czvf - . ) | ssh target_address "(cd DESTDIR && cat - > remotefile.tgz )"
( cd SOURCEDIR && tar cvf - . | gzip -1 -) | ssh target_address "(cd DESTDIR && cat - > remotefile.tgz )"
ssh target_address "( nc -l -p 9210 > remotefile & )" && cat source-file | gzip -1 - | nc target_address 9210
cat localfile | gzip -1 - | ssh target_address cat ">" remotefile.gz

PULL:

ssh target_address cat remotefile > localfile
ssh target_address dd if=remotefile | dd of=localfile
ssh target_address cat "<" remotefile >localfile
ssh target_address cat "<" remotefile.gz | gunzip >localfile

COMPARE:

###This one uses CPU cycles on the remote server to compare the files:
ssh target_address cat remotefile | diff - localfile
cat localfile | ssh target_address diff - remotefile
###This one uses CPU cycles on the local server to compare the files:
ssh target_address cat <localfile "|" diff - remotefile

Push: Push local file to remote server.

Pull: Pull remote file from remote server to local machine.

NX

After updating the free-nx server it might be necessary to run

nxsetup --install

to reinstall the configuration.