Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9185717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:20:42+00:00 2026-06-17T19:20:42+00:00

I am really new to Linux and I apologize if this is rudimentary, but

  • 0

I am really new to Linux and I apologize if this is rudimentary, but I have Google’d to find examples with no clarity and I am confused. (the question relates to a server running CentOs 6)

My questions are:

  1. I am not sure what is the default directory that I should store a .sh file in so that a cron job can run it.
  2. Is the syntax and sequence of my code in .sh file below correct?.

I have tested the TSQL and its fine.

#! SQL="DELETE FROM messages WHERE date < DATE_SUB(CURDATE(), INTERVAL 7 DAY)"

MYSQL_USER="root"
MYSQL_PASS="xxxxxx"
MYSQL_DB="mydb"

I understand that the cron should contain this to do it on a daily basis:

0 0 * * *

But I am just having some apprehension of how to put it all together so I don’t screw things up. A full example or explanation or a reference link would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:20:43+00:00Added an answer on June 17, 2026 at 7:20 pm

    I believe that cron will execute the script from whichever directory it is in, given that:

    • the file has execution permission for the user that cron runs as (usually root if job is configured in the system-wide crontab)
    • the cron line specifies the full path to the script

    So, if your script is /opt/script.sh, specifying this in cron:

    0 0 * * * /opt/script.sh
    

    will execute script.sh each day in 12:00am.

    Please note that if this is the system-wide crontab (/etc/crontab) it should also include a username as which to execute the command:

    0 0 * * * username /opt/script.sh
    

    Also, something to make sure when working with cron is to either use full paths when calling external commands from the script or to set up the PATH variable (either in the script itself or on the crontab file). This is needed because usually the environment in which cron jobs are run is pretty restricted.

    Another thing to have in mind is that if any output is generated by a cron job this output is sent via mail to the user executing the cron. So to have some feedback from the script you have to either set up the system so that the mail message ends up in a mailbox which is read by a human being or the script sends all of it’s output to a log file or syslog.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im really new to linq-to-SQL so this may sound like a really dumb question,
I am really new to the programming but I am studying it. I have
A newbie question (I haven't really created new projects in Eclipse yet): I have
I'm really new to Linux environment and I'm trying to use virtualenv I have
I new in Eclipse,Java and Linux. I search about this issue but I don't
I'm really new to Linux. I Google'd for couple of days, and installed Java
I am new to AVR, but i have programmed PICs before, only this time
I am new to Linux and C++ and have a question about the memory
Hi I'm new to Linux and I really like the idea of writing and
I am really new to java (started learning 2 days ago). Sorry if this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.