wget strips parameters from url - cron

I use the following command in Directadmin:
/usr/bin/wget -O /dev/null https://www.domain-name.com/index.php?parameter=extrap&task=update
Now when I send an output email, it shows connecting to the URL but without &task=update

In *nix operating systems, which you seem to be using, & is a special character that sends the process to the background. You can escape it by quoting the URL:
/usr/bin/wget -O /dev/null "https://www.domain-name.com/index.php?parameter=extrap&task=update"
# Here --------------------^------------------------------------------------------------------^

Related

How to use spaces within cron?

While trying to run a cronjob (I don't have access to the SSH terminal, I only have access to record crons via a cPanel from my hosting) I need to put a space between the cron command itself:
wget -o https://abc.de/aaaaa/bbb ccc/ddd >/dev/null 2>&1
However, the cron job fails reporting:
wget: Unable to find directory https://abc.de/aaaaa/bbb
So how can I use a space there?
In this case, URL encoding should do the trick:
https://abc.de/aaaaa/bbb%20ccc/ddd
but
wget -o "https://abc.de/aaaaa/bbb ccc/ddd"
should work as well.

Using WGET to run a cronjob PHP disable notification email

Im using godaddy as a webhost and id like to disable the email notification that is sent after a cronjob is done. Lucky for me they have been no help but the cronjob area says:
You can have cron send an email every time it runs a command. If you do not want an email to be sent for an individual cron job you can redirect the command’s output to /dev/null like this: mycommand >/dev/null 2>&1
Ive tried several variations of this and nothing seems to fix it.
My command:
wget http://example.com/wp-admin/tools.php?page=post-by-email&tab=log&check_mail=1
Any advice is greatly appreciated.
As the cronjob area says, you need to redirect the command’s output to /dev/null.
Your command should look like this:
wget -O /dev/null -o /dev/null "http://example.com/wp-admin/wp-mail.php" &> /dev/null
The -O option makes sure that the fetched content is sent to /dev/null.
If you want the fetched content to be downloaded in the server filesystem, you can use this option to specify the path to the desired file.
The -o option logs to /dev/null instead of stderr
&> /dev/null is another way yo redirect stdout output to /dev/null.
NOTES
For more information on wget, check the man pages: you can type man wget on the console, or use the online man pages: http://man.he.net/?topic=wget&section=all
With both -O and -o pointing to /dev/null, the output redirection ( &> ... ) should not be needed.
If you don't need to download the contents, and only need the server to process the request, you can simply use the --spider argument

how to send output of ssh to /dev/null

I have a command that wants to connect remote server with ssh.My command is
"ssh -o PasswordAuthentication=no $REMOTE_HOST_IP > /dev/null 2>&1"
When this works the true message comes "Permission denied".It is the true message but i dont want to see message on console so i redirected it to /dev/null.But is still comes.What is the problem
Edit:
I tried as you say and taking 2&1 before /dev/null but still it does not work.But it is strange that it works on my friends computer
SOLVED:Problem is that I assigned the command to a variable and the run it as $command.But when it is set between "" redirection does not work
Look at -n option
-n Redirects stdin from /dev/null (actually, prevents reading from
stdin). This must be used when ssh is run in the background. A
common trick is to use this to run X11 programs on a remote
machine. For example, ssh -n shadows.cs.hut.fi emacs & will
start an emacs on shadows.cs.hut.fi, and the X11 connection will
be automatically forwarded over an encrypted channel. The ssh
program will be put in the background. (This does not work if
ssh needs to ask for a password or passphrase; see also the -f
option.)
Or even on -N
-N Do not execute a remote command. This is useful for just for‐
warding ports (protocol version 2 only).
Try
ssh -o PasswordAuthentication=no $REMOTE_HOST_IP &>/dev/null
ssh -o PasswordAuthentication=no $REMOTE_HOST_IP 2> /dev/null
Try this instead (moving the 2>&1 redirecting stderr before sending it to /dev/null):
"ssh -o PasswordAuthentication=no $REMOTE_HOST_IP 2>&1 > /dev/null"
Note that you are redirecting stderr to stdout with your 2>&1. If you just want to redirect stderr to /dev/null then simply use 2> /dev/null.
Good information about IO Redirection here.

Check Whether a Web Application is Up or Not

I would like to write a script to check whethere the application is up or not using unix shell scripts.
From googling I found a script wget -O /dev/null -q http://mysite.com, But not sure how this works. Can someone please explain. It will be helpful for me.
Run the wget command
the -O option tells where to put the data that is retrieved
/dev/null is a special UNIX file that is always empty. In other words the data is discarded.
-q means quiet. Normally wget prints lots of info telling its progress in downloading the data so we turn that bit off.
http://mysite.com is the URL of the exact web page that you want to retrieve.
Many programmers create a special page for this purpose that is short, and contains status data. In that case, do not discard it but save it to a log file by replacing -O /dev/null with -a mysite.log.
Check whether you can connect to your web server.
Connect to the port where you web server
If it connects properly your web server is up otherwise down.
You can check farther. (e.g. if index page is proper)
See this shell script.
if wget -O /dev/null -q http://shiplu.mokadd.im;
then
echo Site is up
else
echo Site is down
fi

Using wget in a crontab to run a PHP script

I set up a cron job on my Ubuntu server. Basically, I just want this job to call a php page on an other server. This php page will then clean up some stuff in a database. So I tought it was a good idea to call this page with wget and then send the result to /dev/null because I don't care about the output of this page at all, I just want it to do its database cleaning job.
So here is my crontab:
0 0 * * * /usr/bin/wget -q --post-data 'pass=mypassword' http://www.mywebsite.com/myscript.php > /dev/null 2>&1
(I post a password to make sure no one could run the script but me). It works like a charm except that wget writes each time an empty page in my user directory: the result of downloading the php page.
I don't understand why the result isn't send to /dev/null ? Any idea about the problem here?
Thanks you very much!
wget's output to STDOUT is it trying to make a connection, showing progress, etc.
If you don't want it to store the saved file, use the -O file parameter:
/usr/bin/wget -q --post-data -O /dev/null 'pass=mypassword' http://www.mywebsite.com/myscript.php > /dev/null 2>&1
Checkout the wget manpage. You'll also find the -q option for completely disabling output to STDOUT (but offcourse, redirecting the output as you do works too).
wget -O /dev/null ....
should do the trick
you can mute wget output with the --quiet option
wget --quiet http://example.com

Resources