Setting up a Cron User

Posted on 2014-08-04
Last Modified: 2014-08-04
I am attempting to run this command line once/day via a cron to attempt to find all of the recently changed php scripts (as a way to test to make sure a rogue PHP script hasn't been loaded).

find /var/www/vhosts/ -name '*.php' -mtime 0

The script runs from from root, but in my plesk environment it is set up so that root cron jobs DO NOT send out a summary email so as a result I don't get the results sent to me.

I can think of two ways to do this:

1). Add something to the above line so that it sends the output to an email address.

2). Set up a second user in the system that has the right type of privileges to execute this script. I would then change this user to be send summaries.

I need some help with both of these options.  

For #1, can you tell me how I add an email to have the report sent?

For #2, can you tell me how to set up this type of user via Linux Shell script (i.e. direct command lind access).

Thank you.
Question by:pkonstan1
    LVL 23

    Expert Comment

    Option #1:

    Redirect the output to a file, send the file via email:

    find /var/www/vhosts/ -name '*.php' -mtime 0 > output.txt
    mail -s "Script Output" < output.txt
    LVL 23

    Accepted Solution

    Option #2:

    This option is a little more complicated, only because we do not know your system.  You should have a user account already (how do you log in?)

    If that is the case, simply add the job to your cronjobs using crontab -e.

    If you need to add a user, you can use:
    useradd <username>

    Then set the password:
    passwd <username>

    I would then lock the account, so nobody can log in as the new user, kind of like a service account.  The user will still be able to run a cron job
    passwd -l <username>

    Whatever user you use, they will need to have at least read rights to the files and directories in question.

    Author Comment

    Excellent answers. One more question.

    I don't live in the linux world everyday... so things are a little rusty.

    So how would I set up this new user to have "at least read rights" for example to

    LVL 40

    Assisted Solution

    you can use

    chmod +r /var/www/vhosts/

    this will give read perm to the dir /var/www/vhosts/

    but if you want to give read perm to file in /var/www/vhosts/

    then use

    chmod +r /var/www/vhosts/*

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
    Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now