LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 07-27-2011, 03:37 AM   #1
krojther
LQ Newbie
 
Registered: Oct 2009
Posts: 20

Rep: Reputation: 0
Triggering a cron job


Hi,
Is there any way to automatically trigger a cron job each time I log in on my linux account.
Thanks
 
Old 07-27-2011, 03:40 AM   #2
zer0signal
Member
 
Registered: Oct 2010
Location: Cleveland
Distribution: Slackware, Fedora, RHEL (4,5), LFS 6.7, CentOS
Posts: 258

Rep: Reputation: 29
What are you trying to do?
 
Old 07-27-2011, 03:49 AM   #3
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

If you only want to run the 'job' when you log in to your Linux account, then put it (the command, script, whatever is in your cron) in .bashrc/.bash_profile, whichever used in your distro (which you fail to mention what you're using). Don't use cron for jobs you only want to run when you log in (each time you log in), cron is to schedule processes to run on a certain frequency, not when you log in.

Kind regards,

Eric
 
Old 07-27-2011, 07:04 AM   #4
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Quote:
Originally Posted by krojther View Post
Hi,
Is there any way to automatically trigger a cron job each time I log in on my linux account.
Thanks
You don't use cron for this. cron is for running a command at a certain interval.

But the command in your ~/.bash_profile.
 
Old 07-27-2011, 07:05 AM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Quote:
Originally Posted by EricTRA View Post
in .bashrc/.bash_profile, whichever used in your distro (which you fail to mention what you're using).
Actually, this has nothing to do with your distro.

.bashrc executes every time you start an interactive instance of bash (including opening a GUI terminal), and .bash_profile executes every time you log in.
 
Old 07-27-2011, 08:01 AM   #6
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

There are distros that don't have bash_profile per default, hence my mentioning it. LMDE for example doesn't have bash_profile.

Kind regards,

Eric
 
Old 07-27-2011, 08:02 AM   #7
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Quote:
Originally Posted by EricTRA View Post
Hi,

There are distros that don't have bash_profile per default, hence my mentioning it. LMDE for example doesn't have bash_profile.

Kind regards,

Eric
But you can create it.
 
Old 07-27-2011, 08:18 AM   #8
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

Of course you can but that's not the point. If you have one or the other then why would you create an additional one that's not there by default when you can put the same in the one you have? I just am trying to avoid the OP getting confused, hence not referring to something he can create if it's not there but only to what's available per default, taking into consideration that the OP is a newbie.

Kind regards,

Eric
 
Old 07-28-2011, 01:13 PM   #9
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 548

Rep: Reputation: 116Reputation: 116
What's the difference between .bash_login and .bash_profile then?
 
Old 07-28-2011, 06:11 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,326

Rep: Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364
Traditionally, its

Code:
# csh
.login

# ksh
.kshrc
.profile

# bash
.bashrc
.bash_profile
but I believe that bash may read .profile if it can't find .bash_profile. I've never seen .bash_login.
 
  


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
linux cron job duplicate job question cpthk Linux - Newbie 4 09-11-2009 08:52 PM
Cron Job chetansharma_softeng Linux - Newbie 7 01-12-2009 06:14 AM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
Cron Job newbie_adm Linux - Newbie 2 06-05-2006 11:52 PM
CRON Job tommytomato Fedora 12 09-13-2004 12:38 AM


All times are GMT -5. The time now is 04:18 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration