LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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, 10: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 11:37 PM. Reason: post left out backslash
 
Old 05-18-2017, 01:38 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,329

Rep: Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745
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, 02: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, 02:21 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,108

Rep: Reputation: 7138Reputation: 7138Reputation: 7138Reputation: 7138Reputation: 7138Reputation: 7138Reputation: 7138Reputation: 7138Reputation: 7138Reputation: 7138Reputation: 7138
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, 03: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 03:24 AM.
 
Old 05-20-2017, 12:22 PM   #6
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,647

Rep: Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149
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 12:23 PM.
 
  


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 03:16 PM
Need help with cron job syntax. Thank you. urglik Linux - Newbie 5 09-08-2014 01:27 PM
Syntax for : Receiving email once Cron job is completed Linux_Newbee83 Linux - Newbie 5 01-04-2012 10:11 PM
Cron job issues Alan87i Ubuntu 21 07-14-2011 03:49 AM
Cron Job Syntax for a task in seconds AJones Linux - Software 2 07-22-2005 01:56 PM

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

All times are GMT -5. The time now is 07:14 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