LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-17-2017, 09:10 PM   #1
Tempoetic
LQ Newbie
 
Registered: May 2017
Posts: 2

Rep: Reputation: Disabled
Red face Cron Job syntax issues


Hi Linux guru's, newbie here.

I am struggling the get my Cron Job working and suspect it is because I am not escaping a "%" in my password correctly. I know, it's bad to include pw etc, however, once this is working I will disable any inclusion of it anywhere external.

I should say I'm doing this from cPanel as I'm not a hard core Linux buff.
After many dozens of attempts, I am stumped. Here's what I'm trying to do.

mysqldump --opt -Q -u USERNAME -p 'XXXX\%X' --all-databases > /home/USERNAME/backups/databases.sql

Where "X" is password chars, "%" is included in pw and the backslash is my attempt to escape the % in the password.

Result (via email) is:
/usr/local/cpanel/bin/jailshell: -c: line 0: unexpected EOF while looking for matching `''
/usr/local/cpanel/bin/jailshell: -c: line 1: syntax error: unexpected end of file

Any help greatly appreciated

Last edited by Tempoetic; 05-17-2017 at 10:37 PM. Reason: post left out backslash
 
Old 05-18-2017, 12:38 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,862

Rep: Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598
Well, normally '\' should do it I would have thought .
Anyway, I would recommend putting all that into a shell script and just calling the script from cron.
Its more powerful/flexible and should also save you having to escape '%'.

PS: you could try double \\, but scripts are a better soln anyway.
 
Old 05-18-2017, 01:02 AM   #3
Tempoetic
LQ Newbie
 
Registered: May 2017
Posts: 2

Original Poster
Rep: Reputation: Disabled
Hi Chris

Thanks for responding.

Tried the double \\, no luck.

Forgive my ignorance, but to create the shell script would I just paste that line in a blank file and name it something like "myBackupScript.sh"?

Thanks.
 
Old 05-18-2017, 01:21 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,493

Rep: Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532
It is not that simple. Cron runs using sh, and the command line interpreted differently. So putting everything in a script and running it with bash may definitely solve this issue (and also other similar ones).
I'm not really sure you need to protect % at all, there can be other problems.
You can try to create a shell/python/perl/awk/whatever script to print the passed command line arguments (just to check how cron handles your entry).

Also using cron you may need to take care about stdout and stderr yourself, probably there will be some other information (this is another reason to use a shell script - you can handle it better).
 
Old 05-18-2017, 02:22 AM   #5
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
There is no space between -p and the password,

Code:
# mysql -p 'mypass'
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
# mysql -p'mypass'
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
see in the first how it says "using password: NO", having the space means prompt for password but I did not pass one, it assumes mypass is the name of the database now.

in the second, it actually passed mypass as the password but as that isn't my actual password it failed, still it says "using password: Yes" as 'mypass' is now seen as the password. you need to eliminate that space, mysqldump has the same behavior as the mysql client in this regards.

Last edited by r3sistance; 05-18-2017 at 02:24 AM.
 
Old 05-20-2017, 11:22 AM   #6
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,741

Rep: Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791
Backslash escapes the % for cron, but you must do it outside the ticks so the pogram does not see the backslash (because the shell removes it).
Code:
mysqldump --opt -Q -u USERNAME -p 'XXXX'\%'X' --all-databases > /home/USERNAME/backups/databases.sql

Last edited by MadeInGermany; 05-20-2017 at 11:23 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Issues running cron job linuxandtsm Linux - Newbie 2 09-16-2014 02:16 PM
Need help with cron job syntax. Thank you. urglik Linux - Newbie 5 09-08-2014 12:27 PM
Syntax for : Receiving email once Cron job is completed Linux_Newbee83 Linux - Newbie 5 01-04-2012 09:11 PM
Cron job issues Alan87i Ubuntu 21 07-14-2011 02:49 AM
Cron Job Syntax for a task in seconds AJones Linux - Software 2 07-22-2005 12:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration