Tera term macro how to SCP a file - teraterm

Does anyone know if TERA TERM allows me to copy a file on my server to my local PC?
My job does not allow me to install any other software on this server, so I plan to create a macro with whatever tera term offers.
For example, I want to copy a file name test.bin located in /tmp to my PC C:\test\logs.
I tried using TERA TERM "SCPSEND," but it did not work; it gave me a pop box with the error "File open error." I assume this command is only meant to copy files into the host server, not from the host server to my local PC.
SOURFILE = '/tmp/test.bin'
DESTFILE = 'C:\test\logs'
;; Send a file.
scpsend SOURFILE DESTFILE
;; Confirm a scp process.
do
mpause 5000
sprintf2 str 'ps -ef |grep -v grep |grep -c scp'
sendln str
waitln '0' '1'
loop while result != 1
;; Do next macro after finishing the file sending.
sendln 'echo SCP finish'
;; Exit this macro script.
end

Related

redirect the ouput of command into a socket on linux

I'm using netcat to connect to a server.
the problem is that i want to send somme non printable to the server caracters.
I wanted to achieve this with a command redirection in linux.
lets say this is the command: nc hostname port
so when i checked the file descriptors of the command nc in the folder: cd /proc/$(pidof nc)/fd is saw the there was another fd with number 3 that conserns the socket. 3 -> socket:[1675643]
the problem is that i wanted to redirect the output of let's say echo -ne '\xff\x0f\xab\xde' > ./3 to the socket.
I couldn't do so and the ouput is: bash: ./3: No such device or address
One cannot output something to a socket which is opened only by another process.
In order to first use interactive input/output and afterwards send the echo string, you can do:
(cat; echo -ne '\xff\x0f\xab\xde')|nc hostname port
(press the EOF character Ctrl-D to end your input and start the echo).

Wifi disconnected before init.d script is run

I've set up a simple init.d script "S3logrotate" to run on shutdown. The "S3logrotate" script works fine when run manually from command line but the script does not function correctly on shut down.
The script uploads logs from my PC to an Amazon S3 bucket and requires wifi to run correctly.
Debugging proved that the script is actually run but the upload process fails.
I found that the problem seems to be that the script seems to run after wifi is terminated.
These are the blocks I used to test my internet connection in the script.
if ping -q -c 1 -W 1 8.8.8.8 >/dev/null; then
echo "IPv4 is up" >> *x.txt*
else
echo "IPv4 is down" >> *x.txt*
fi
if ping -q -c 1 -W 1 google.com >/dev/null; then
echo "The network is up" >> *x.txt*
else
echo "The network is down" >> *x.txt*
fi
The output for this block is:
IPv4 is down
The network is down
Is there any way to set the priority of an init.d script? As in, can I make my script run before the network connection is terminated? If not, is there any alternative to init.d?
I use Ubuntu 16.04 and have dual booted with Windows 10 if that's significant.
Thanks,
sganesan7
You should place you scrip in:
/etc/NetworkManager/dispatcher.d/pre-down.d
change group and owner to root
chown root:root S3logrotate
and it should work. If you need to do this for separate interface place script in
create a script inside
/etc/NetworkManager/dispatcher.d/
and name it (for example):
wlan0-down
and should work too.

How to copy output of command line from remote, to local clipboard via ssh

I am using HPC on campus and it is CentOS. I asked administrator to install xclip in HCP. But he said it would endanger to HPC. I am not root user. I am wondering whether there is a way to I can copy output of command line to clipboard directly without installing xclip. I do not want to use mouse to select and copy. Is there a way in terminal that it can redirect the output to clipboard?
This is sort of hackish:
Start a local xclip server:
#!/bin/bash
while true
do nc -l localhost 8888 | xclip
done
Connect with a reverse port redirection:
ssh <something something> -R 8888:localhost:8888
On the remote write what you want to copy to that port. Some options are:
echo "I WANT TO COPY THIS" | nc -C localhost 8888 #close on eof varies with version
Or
echo "I WANT TO COPY THIS" > /dev/tcp/localhost/8888
If both fail, you may still try with perl or python.

Send Control signals to another machine

I am attempting to automate throughput measurement of a WLAN using iperf ,so i have a script that will initiate the server (iperf -s -i1 -w2M -t300) and save the contents of the output,send an email and place file in a corporate directory. However, i still have to execute the client side remote command manually (iperf -c 192.168.0.150 -w2M -i1 -t300) .I want to execute one script for both task either by :-
a) Start an SSH process in the script and execute the command.
b) Pass an iperf application signal to the remote PC that will induce a process execution.
Please note that by SSH, it will achieve my goal but it will defeat the purpose of my exercise, i want to do functions calling between two machines
I want to have a running application on both sides and the process executed on one.
#!/usr/bin/bash
cwd=$(pwd)
export PATH=$PATH:$cwd
read -p "Name of the file" FXX
read -p "Number of minutes" MMM
iperf -s -i1 -w2M -t"$MMM" | tee "$FXX.txt"
source iperfserver
source /usr/bin/iperfserver
trap exit INT
sshpass -p 'hello' scp "$FXX.txt" bharat#hello:
echo "Hello"|mailx -s "Hello " -a "$FXX.txt" bharat#hello.com
Here is the iperfserver script, so i am trying to coordinate the efforts between the scripts but i am not able to so as soon as i start iperf -s the script stops and i cannot create a simultaneous process. I will try to research on this but if you can help me i will be grateful.
#!/usr/bin/bash
cwd=$(pwd)
export PATH=$PATH:$cwd
sshpass -p 'hello' ssh 192.168.0.101
iperf -c 192.168.0.150 -w2M -i1 -t300
Thanks
Bharat C P

telnet automation script fails sometimes

I am running the following simple telnet script which just logs into a machine and exits.
The same script works fine (goes through 1000 iterations) from one Linux server but fails (consistently) from another Linux server (fails after say 200 attempts).
In failure case, the number of iterations it takes to fail varies but failure is persistent.
#!/usr/bin/perl
use Net::Telnet;
my $loop = 0;
my $dumpfile = "dump.log";
my $inputfile = "input.log";
for ($loop =1; $loop <=1000; $loop++) {
print "===============Loop: $loop =====================\n";
$telnet = new Net::Telnet ( Timeout=>20, Errmode=>'die');
print "$telnet\n";
$telnet->open('sys-007');
$telnet->dump_log($dumpfile);
$telnet->input_log($inputfile);
$telnet->waitfor('/login: $/i');
$telnet->print('root');
$telnet->waitfor('/Password:$/i');
$telnet->print('007');
sleep 2;
$telnet->print('exit');
print "=================================================\n";
}
Script exits with:
pattern match read eof at ./telnettest.pl line 15 (i.e, waitfor('/login: $/i'); Line)
I tried the following to see what is going wrong:
In the client machine: (sys-007)
tcpdump -nvvv -w test.txt host <Server IP>
strings test.txt has:
Successful attempt Log:
sys-007 (ttyp0)
^Fl$4
^!^Fl$
login:
^Fl$4
^Fl$4
root
^(^Fl*
root
bP"u
^Fl*4
bP5u
^.^Fl*
Password:
^Fl*4
^Fl*4
007
^7^Fl6
^Fl64
^9^Fl6
Terminal type? [xterm]
^Fl64
^Fl64
exit
^Fl<4
^Fl<
exit
^Fl<
Failed Attempt:
sys-007 (ttyp0)
*^hn
+^hn
No login: prompt!
In server machine: (Linux Server)
[telnet#server]~% netstat --inet -a | grep telnet | grep sys-007
There are no TIME_WAIT or CLOSE_WAIT sockets.
Please tell me what should I look for to find out what is going wrong.
Are you able to login normally after this? I'm guessing this other server is cutting you off because you've made too many connections.
What I suspect is that the telnet program is waiting for the prompt. I usually use the below format to define the prompt, so that the script usually is able to find the prompt from the below given options.
test = new Net::Telnet (Timeout => 3000 , Prompt => '/[%#\$>?:] $/' );
$test->open($IPAddress1);
$test->login($Login,$Password1);
my #input=$test->cmd("uname -a\n");
print "Connected to : #input";
#input=$cmd->cmd("pwd\n");
Please let us know if you still face the problem.

Resources