Response
stringlengths 8
2k
| Instruction
stringlengths 18
2k
| Prompt
stringlengths 14
160
|
---|---|---|
0
#!/bin/bash
cat /dev/null > Body.text
DATE=`date +%b/%d/%Y`
BACKUP_DIR="/home/user/Redmine/tmp"
DB_NAME="xxx"
DB_USER="xxx"
DB_PASSWORD="XXXXXX"
Redmine_Root="/home/webuser/apps/redmine"
echo "Redmine Backup Directory is $BACKUP_DIR" >> /root/Body.text
rm -rf $BACKUP_DIR/files* $BACKUP_DIR/Redmine*
# -- MySQL
echo "`date` at Redmine's MySQL db Backup on" >> /root/Body.text
mysqldump -u $DB_USER -p$DB_PASSWORD $DB_NAME > $BACKUP_DIR/Redmine.sql
gzip $BACKUP_DIR/Redmine.sql
rm -f $BACKUP_DIR/Redmine.sql
#........Redmine
echo "`date` at REDMINE_Files Backup " >> /root/Body.text
#Create back up for Files
echo "Backing up Redmine attachments..."
rsync -a $Redmine_Root/files/ $BACKUP_DIR/files/
echo "Packing into single archive redmine files"
tar -zcvf $BACKUP_DIR/redminefiles.tar $BACKUP_DIR/files
rm -rf $BACKUP_DIR/files/
#Create a single tar file
echo "Create Backup of Single File" >> /root/Body.text
cd /home/user/Redmine
tar -cvf Redmine`date +%b%d%y`.tar tmp/
tar -cvf /home/user/Redmine`date +%d%b%y`.tar /home/user/Redmine/tmp
rm -f $BACKUP_DIR/redminefiles* $BACKUP_DIR/Redmine*
rm -f $BACKUP_DIR/Redmine.sql.gz
#Cleaning Up
echo "Delete five days olderbackup" >> /root/Body.text
find /home/maitreya/Redmine/* -mtime +5 -exec rm -rf {} \;
#Sending Report
/usr/bin/mutt -e "set realname=\" Redmine-Backup\" " \ -s "Redmine Backup on $DATE" [email protected] -c [email protected] < /root/Body.text
Share
Improve this answer
Follow
edited Sep 1, 2015 at 11:09
answered Sep 1, 2015 at 8:53
some_other_guysome_other_guy
3,40444 gold badges3737 silver badges5555 bronze badges
1
can you tell me about this Body.text what it does?. I am not getting why it is being used?
– Prateek Naik
Sep 18, 2017 at 9:27
Add a comment
|
|
Need a script solution to take daily back-up of a DB and send a mail for it.
The code makes a back-up for mysql DB and the files involved (as in most use cases)
|
Shell script to take up daily DB backup (for something like Redmine, etc)
|
As far as I can tell, Azure Backup doesn't support backup VM instance yet.
|
Can I backup VM instances using Azure Backup Services, with Site Recovery Vault?
|
Backup VM instances using Azure Backup Services
|
the behaviour you're trying to achieve is the default behaviour on Android. So I believe that on your question, less is more.
AndroidManifest.xml:
remove all parentActivityName from it. It really does not much at all.
remove all launchMode those specific edge cases, unless you have a specific reason and a non-default behaviour, do not use them.
intent parameters you're passing to activities don't get messed by any of those manifest details, I don't think they have anything to do with your issue. On any activity you should be able to call getIntent().getExtras() and access any parameters passed to it, no matter how many times you exit and enter the app.
you do not need to save/restore the intent parameters during onSaveInstanceState and onRestoreInstanceState. Those callbacks are for current state, not for parameters passed to it. Those are different things.
back: that happens automatically. You cannot finish(); the previous activity when calling the next one.
up: it's just a matter of overriding the parentActivityName0
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
finish(); // this finishes and the previous will be shown.
return;
// other menu items ?
}
}
if I try to navigate up to B, it crashes because I don't have the
extras and the activity has been terminated. What is the best
behaviour? Keep them open? Recreate them?
do NEVER say "it crashes" on StackOverflow without providing a stacktrace and the lines of code around that stacktrace. That's one of the main reasons I downvote people.
If it crashes, ask about that crash, do not mess-up the automatically-default navigation to "try to fix it"
|
I have an app with some normal behaviour but I still dont know what I am doing wrong.
Activity A calls --> Activity B
I pass strings/ints from one activity to the other (Intent.putExtra())
I had declared my activities as single instances and declared who is parent of who in my manifest, but when I open other app and then go back to mine, the activity I was in is the only still alive.
If I remove the'singleInstance', then my navigation works but the ones that receive strings from the intent (previous activity) crashes.
I want to be able to:
When I am in my app, navigate up/back through my activities.
If I leave my app and come back, still be able to navigate up/back in my app.
Considering I pass values between activities with Intent.putExtra("key", "value")
I think is all related with the Back/Up Navigation and the android:launchMode=["multiple" | "singleTop" | "singleTask" | "singleInstance"] but I can't find the perfect solution.
Update:
A --> B --> C
A->B: A putExtra; B getExtra
B->C: B put Extra; C get extra
If I go to C, leave the App and then come back to the app, the app is in C, and if I try to navigate up to B, it crashes because I don't have the extras and the activity has been terminated.
What is the best behaviour? Keep them open? Recreate them?
|
Android app lifecycle Up and Back
|
0
That's sync software, try goodsync. It can meet your requirements like select the folders, the targeted folders change when the source change (added, edited etc).
Share
Improve this answer
Follow
answered Jan 7, 2015 at 5:18
sara Monisara Moni
1
0
Add a comment
|
|
I am looking for a backup kind of software (for windows os ) that backs up required data to external hard disk. It should
-> Gives user the option to select the folder(s) to backup
-> If there are any changes in the source(file name renames, addition or deletion of files), the same changes should be done in the destination(in external hard) when the hard disk is connected to the system.
|
A backup software for windows that backs up selected folder and maintains the destination and source identical
|
You would basically remove the subscription and start again, i.e. with another backup & restore, and then following the steps you used to initially setup the subscription.
|
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have some quetions about tracsation replication in sqlserver 2008 r2,as you know,when your database is very large,you can use backup to initialize tracsation replication,this will not need snapshotfiles,
what's my quetion is when my subcriber is wrong,how I can reinitialize the subscription.
|
how to reinitialize the subscription when I did transaction replication with backup [closed]
|
What happens when you manually re-mount the drive as vfat?
umount /MOUNTPOINT
mount -t vfat -v /dev/sdXX /MOUNTPOINT
|
I am trying to help a friend back up some files to an external USB drive from a machine running Ubuntu. The drive is a 1.36 TB big and is using NTFS. From what I can tell I need to reformat it to FAT32. But FAT32 does not seem to be able handle a drive that big.
I tried mkfs -t vfat but it still shows as NTFS on the Ubuntu machine. Which is funny because when I plug it into my Windows 7 machine to format it there it shows up as FAT32. I also tried SwissKnife but it only offered me FAT16 - I want FAT32.
What can I do?
|
How to format large USB external drive to FAT32 for Ubuntu
|
You need to first grab the contacts in Android look at the example code in the AOSP project for the people app, that will show you the way that Google is doing it officially, which doesn't necessarily make it the best method, but it's a lot easier to re-tool their code than write it all from scratch.
Here's how to get started with the Android build environment:
http://source.android.com/source/initializing.html
Here's another question, similar to yours that might help with the contact data:
How to read contacts on Android 2.0
On your end, you need to setup a SQL server of some kind... and one of the fields just needs to be "Last Updated", either add a date to that field, or a revision number that you're tracking elsewhere and decide to update based on the query out of that field.
|
I am creating an app to backup contacts to a webserver. I am still new to android development so I can't think of the logic to do this. I know that the contact id is not constant and it can change. So how can I keep track of changed data to existing and new contacts?
|
Logic for backing up contacts
|
0
It's not a dump tool but I use rsync which allows incremental backups between 2 filesystems on a running system.
for example
rsync -aSXvH /srcdir /target_dir
Share
Improve this answer
Follow
answered Aug 23, 2011 at 15:41
JJ.JJ.
5,42533 gold badges2626 silver badges3131 bronze badges
4
Thanks, i'll try it a bit later. Does it support deltas?
– tijagi
Aug 23, 2011 at 16:21
Yes - it will only sync what has changed since the last sync.
– JJ.
Aug 23, 2011 at 16:22
But it doesn't suit in that case. If a directory always updates, a snapshot will have collisions while rsync.
– tijagi
Aug 25, 2011 at 15:18
Explain what you want more clearly and you may get more help.
– JJ.
Aug 25, 2011 at 16:33
Add a comment
|
|
I'm looking for a backup tool for ext4, which can take a copy from a running fs like /var with no collisions after recover such fs. I know BSD dump has an '-L' option, which tells him to work on a snapshot. But nor dump nor dumpe2fs from repository have such option. I've read about a patchset for ext4 providing snapshot support, but replies about it are very different, so i'm here to ask about your experience with this patches.
|
Backup or snaphot tool for ext4
|
moved to https://serverfault.com/questions/230062/good-backup-solution-for-xen-virtual-machines
|
we are looking for a backup solution for our xen servers that meets the following requirements:
makes backups while machines are running
has easy to use disaster recovery without depending on complex infrastructure in case of a disaster
can backup all kinds of linux and windows machines
sends some kind of message if something is not working. We dont want to monitor everything manually
We tried Acronis Backup & Recovery 10 virtual edition but it is not compatible with linux vms. Bacula does not seem to have good disaster recovery, as far as we know.
My question:
What are good backup solutions for our requirements?
Thanks advance for your answers.
Cheers
Arne
|
Good backup solution for Xen virtual machines?
|
-1
you can try git LFS (https://git-lfs.github.com/) after zipping the file. It is for handling large files in git. you can have similar versioning system of git with support for large files.
Share
Improve this answer
Follow
answered Jul 14, 2022 at 4:53
Venkataraman RVenkataraman R
12.5k22 gold badges3333 silver badges6262 bronze badges
Add a comment
|
|
I'm currently on a team that uses Postgres and a few other SQL Server databases. We're in a fairly limited environment and do not have access to major cloud provides like AWS, GCP, etc. As a part of each release cycle, I take a snapshot of production's Postgres DB, store the backup on the company's OneDrive and provide a link to all the developers to download. Our Postgres DB is around 3.5GB using the directory format. Each developer then downloads the backup and restores it locally. As for SQL Server, I've created isolated sandboxed schemas in each SQL Server DB and created a user login that can only access them and is barred from the production schemas. Particularly with Postgres, it's difficult to keep all of the developers in sync, especially since we have different schemas for each release, and teams may make modifications to the schema during their development. Is there a better way to store and distribute these developer DB snapshots, say, via Git or JFrog Artifactory?
I've found a very limited number (maybe this isn't a typical issue then) of topics here. A few of the comments suggest using drupal but that's not really an option for my team.
Also, I've seen a lot of posts about production backup solutions. I'm not searching for that; this is purely for managing a distributed database backup across team members for different releases.
Edit 1:
Perhaps this should be its own question: It's not only the snapshots each release cycle that are an issue. My team is working on a monolithic application comprised of several submodules. During a given sprint, one team might add 5 new tables to a DB. Members of any one sub-team are often required to transition to other sub-teams mid-sprint, so this can present a challenge if their database doesn't have the same schema updates as the sub-team they're switching to.
|
How to best share DB backups among dev teams?
|
-1
I assume 'll' is 'ls -l'
opendir("/storage/mount_usb") will work since the directory exists even if nothing is mounted on it.
'll /storage/mount_usb/movie.mp4 ' works if the required data is still in file system caches.
'll /storage/mount_usb' does not work since you want to list all files in the directory. To do this, the file system tries to access the device which you have unplugged without telling the file system.
Share
Improve this answer
Follow
answered Jan 30, 2018 at 10:29
Reine StenbergReine Stenberg
9644 bronze badges
3
how can i clear file system caches to get proper information
– MIke
Jan 30, 2018 at 10:39
You should unmount the device before unplugging it. If you don't unmount file systems before unpluggin them you risk corrupting the files
– Reine Stenberg
Jan 30, 2018 at 10:41
This command will clear directory entries and inodes 'sync; echo 2 > /proc/sys/vm/drop_caches'
– Reine Stenberg
Jan 30, 2018 at 10:54
Add a comment
|
|
i'm working on linux centos 7.4,where i mounting USB device with '/dev/sdxn'.
mounted directory present in '/storage/mount_usb'(ex:inside one file is present like movie.mp4).
if i manually unplugged (without unmounting it) and i check command 'lsblk' their '/dev/sdxn' is not present, so here looks like ok for me.
but when i run command 'll /storage/mount_usb/movie.mp4' then it's still showing some of the data and we can also able to open file in read mode(using open,fopen systemcall).
command 'll /storage/mount_usb/movie.mp4 '.
i.e -rwxrwxrwx. 1 root root 1506417406 Jan 29 16:17 /storage/mount_usb/movie.mp4
but when i run command 'll /storage/mount_usb'.
i.e- ls: reading directory /storage/mount_usb: Input/output error total 0
and if i use opendir("/storage/mount_usb") then it will also open successfully and not return any error code.
i'm not able to understand why data is still showing after unplugged USB.
|
mount directory still showing data after remove USB manually
|
0
Since your sda isn't very large and a lot of it is used anyway, I'd create a complete backup of the block device. Your sdb, however, is very large and used only to a small part. Of that I'd create a file system backup.
Boot your server with a Ubuntu live CD and become root (sudo su -).
Attach your backup medium (I assume it's mounted as /mnt/backup/ in the following).
Create a block device backup of sda: cat /dev/sda > /mnt/backup/sda
Mount your sdb (I assume it's mounted as /media/3TB1/ in the following).
Create a file system backup of sdb: rsync -av /media/3TB1/ /mnt/backup/sdb/
For restoring the backup later:
Boot your server with a Ubuntu live CD and become root (sudo su -).
Attach your backup medium (I assume it's mounted as /mnt/backup/ in the following).
Restore the block device backup of sda: cat /mnt/backup/sda > /dev/sda
Mount your sdb (I assume it's mounted as /media/3TB1/ in the following).
Restore the file system backup of sdb: rsync -av /mnt/backup/sdb/ /media/3TB1/
There are more fancy ways of doing it for sure. But this routine worked for me lots of times.
Share
Improve this answer
Follow
answered Aug 3, 2017 at 9:59
AlfeAlfe
57.7k2020 gold badges110110 silver badges165165 bronze badges
1
Downvotes (there is one) should be commented to help improve the answer.
– Alfe
Aug 4, 2017 at 15:04
Add a comment
|
|
I have a server with the following disk structure:
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 219G 192G 17G 93% /
tmpfs 16G 0 16G 0% /lib/init/rw
udev 16G 124K 16G 1% /dev
tmpfs 16G 0 16G 0% /dev/shm
/dev/sda2 508M 38M 446M 8% /boot
/dev/sdb1 2.7T 130G 2.3T 5% /media/3TB1
I am interested in making backup of the whole server on my local machine. When the time comes I want to be able to restore a new server from my local machine backup. What procedure do you recommend?
I tried rsync, but the indexing took extremely long so I aborted it. Than I used scp, and well, it is currently working. There is lots of symbolic links that weren't transferred to the local machine, and I worry I won't be able to restore it later on.
|
Make a backup of the whole server that can be restored later
|
How is the 7GB of data layout? How many files? Which kind of files (DB, pictures, text, docx, doc)? What is the average/smaller/bigger file size? How do the files change: new files added, files completely changed, some bytes changed/appended to some existing files?
Those are meaningful information to pick up to right way of backup...
For instance, if your files are not small, just copying to another folder would make the trick (you can find some algorithm for directory-level diffs in this unit).
7 GB is huge for a zip archive. Of course, you can handle zip on such size, but IMHO it is not the right format to use for an incremental backup.
One issue with the zip format is that to update a file, the previous version has to be deleted, therefore the whole zip content has to be rewritten... at best, the file content is moved.
So if you want to refresh the backup on a regular basis (each day e.g.), the regular archive format is not the best candidate.
I'd suggest using some flat-file format, like our Open Source Synopse Big Table, and store either the plain content, either a compressed version (don't use zip/deflate format, which are slow, but for instance our SynLZ algorithm which is faster than any other - even faster than LZO - for compression). If compression is faster than your disk access, backup will be faster: zip/deflate is slower than Disk access for compression, but SynLZ is much faster, so you'll save time by SynLZ-compressing the content.
With Big Table, you can use in-memory meta-data for the file attributes (name, version, date, attributes, previous version ID...), then let the compressed content on disk.
If the files are huge, and only some bytes will change, consider using a binary diff instead of writing the whole content every time, to store only the difference between main versions. Here is one unit which is very fast, and we use for storing diff between versions for the file versioning part of our SynProject tool.
|
There is a folder - 7 Gb with a big amount of binary files. An average size of the binary file is around 100 Kb. These files are compressed in ZIP archives. An average size of that ZIP archive is around 2 Mb. Therefore I need to make the backup of the ZIP archives.
And I need to make the backup of the whole folder. It can be without a data compression. A main requirement is the fast backup. Therefore it must be a possibility to restore files from the backup.
For example, an archive without a data compression can be used, but adding and extracting of files must be fast. Or fast copying can be used.
Please, tell me how to do this in Delphi or tell your suggestions.
Thanks!
|
Delphi: own files' Backup
|
4
Assuming xp_cmdshell is enabled and that all files will end with yyyyMMddhhmm.bak:
CREATE TABLE #x(n VARCHAR(2048));
DECLARE @cmd VARCHAR(2048), @fn VARCHAR(2048), @folder VARCHAR(255);
SET @folder = 'E:\sqlbackup\MerchantAPIReport\'; --'
SET @cmd = 'dir /b "' + @folder + 'MerchantAPIReport_backup_*.bak"';
INSERT #x EXEC master..xp_cmdshell @cmd;
SELECT TOP (1) @fn = @folder + n
FROM #x
ORDER BY CONVERT(DATETIME,
STUFF(STUFF(LEFT(RIGHT(n, 16), 12), 11, 0, ':'), 9, 0, ' '))
DESC;
-- whatever you do, don't try to construct this yourself.
-- I'll fill in the blanks for you. <sigh>
RESTORE DATABASE [MerchantAPIReport] FROM DISK = @fn
WITH FILE = 1,
MOVE N'MerchantAPIReport' TO N'D:\SQLData01\MerchantAPIReport.mdf',
MOVE N'MerchantAPIReport_log' TO N'F:\SQLLog\MerchantAPIReport.ldf',
NOUNLOAD, REPLACE, STATS = 10;
-- RESTORE DATABASE ... FROM @fn ...; -- fill in the rest here
DROP TABLE #x;
Share
Improve this answer
Follow
edited Jul 2, 2012 at 5:42
answered Jul 2, 2012 at 2:17
Aaron BertrandAaron Bertrand
276k3838 gold badges473473 silver badges502502 bronze badges
3
@user1484403 did you check that I copied your folder name correctly? Did you check what is contained in #x?
– Aaron Bertrand
Jul 2, 2012 at 5:05
@user1484403 sorry, but I don't understand which part of your question you actually want to keep. If you just want the .bak file with the latest timestamp, the code I've provided should be all you need. If there are additional requirements you haven't stated, please state them or start a new question.
– Aaron Bertrand
Jul 2, 2012 at 12:06
sorry i have juz edit to another version
– user1484403
Jul 3, 2012 at 3:16
Add a comment
|
|
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
I would like to restore a database backup file .bak to a server but there are a few .bak file with different timestamp, for example :
dbname_backup_201210290200.bak
dbname_backup_201210300212.bak
dbname_backup_201210310213.bak
|
Select .bak file with latest timestamp [closed]
|
2
The simplest possible way would be to just create a copy in the parent directory or other convenient location.
You could create such aliases to make it easier:
alias bak-cur-dir='(DIR="${PWD##*/}" && cd .. && cp -r "$DIR" "$DIR".bak)'
alias res-cur-dir='(DIR="${PWD##*/}" && cd .. && rm -rf "$DIR" && mv "$DIR".bak "$DIR") && cd .. && cd -'
Share
Improve this answer
Follow
edited Sep 8, 2021 at 14:18
answered Sep 8, 2021 at 10:53
JorenarJorenar
2,77455 gold badges2626 silver badges6262 bronze badges
Add a comment
|
|
I would like to do the following:
Backup the current folder
Run some test files
Restore the backup (delete all changes from previous commands)
Delete backup
Unfortunately I do not have Git available. Otherwise I would do
git add .
git commit -m "backup"
# run commands
git checkout .
|
How to temporarily backup the current folder?
|
2
You can setup a secondary namenode which will automatically take a backup of namenode periodically. In cases of namenode failure, you can use the secondary namenode to regenerate the namenode metadata.
You can also set up HA (high availability) in your cluster, so that if the namenode goes down, the cluster will automatically switch to the the alternate namenode created during HA. Please read more about HA here : http://hadoop.apache.org/docs/r2.3.0/hadoop-yarn/hadoop-yarn-site/HDFSHighAvailabilityWithNFS.html
Share
Improve this answer
Follow
edited Dec 15, 2015 at 10:57
answered Oct 6, 2014 at 14:19
AmarAmar
3,83511 gold badge2424 silver badges2626 bronze badges
Add a comment
|
|
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'd like to ask what is the best way to keep my hadoop cluster safe and schedule periodic backups.
Is it possible to do a live backup of the namenode? How do I set up a backup node?
|
Hadoop HDFS backup [closed]
|
1
Why are you calling the method twice here?:
do {
create_backup_folders();
} while (create_backup_folders() == false);
That's going to make things confusing, as you're now discovering. Just call the method once on each loop iteration and store the result of the method. Then use that stored result in the loop condition:
var canContinue = false;
do {
canContinue = create_backup_folders();
} while (canContinue == false);
Share
Improve this answer
Follow
answered Nov 15, 2015 at 1:28
DavidDavid
213k3737 gold badges200200 silver badges281281 bronze badges
3
1
Definitely your suggestion look nicer. It still very unclear why even have a loop - CreateDirectory can't half-succeed, so calling it once should be enough (especially since it will create all necessary sub-folders too)
– Alexei Levenkov
Nov 15, 2015 at 1:39
@AlexeiLevenkov: True, this entire block of code seems a bit silly. Though perhaps that has something to do with "so i cant use the best solution", which is a statement I can't quite wrap my head around :-/
– David
Nov 15, 2015 at 1:41
thy david, there are lot of solutions what I must llearn before publish my first usable soft :)
– cenekhavelka
Dec 2, 2015 at 22:25
Add a comment
|
|
I want ask an easy question about my code in c# .... I know that there are lot of topics with same or similar topic/code result. But I need to hand in my code to school, so I can't just use the best solution on Stackoverflow or another page. I showed my code to my teacher and now need to fix a little bug.
The Code is about backing up files with a console report, so in first step I check if a folder exists. Second step is to report that the folder exists or doesn't exist, if it doesn't the code creates this folder and rechecks ...
SITUATION : CONSOLE REPORT
folders doesnt exist:
02:02:06 directory for backup Exist ... can continue
02:02:05 directory for backup DOESNT EXIST ... creating required folders...
folders exist :
02:02:55 directory for backup Exist ... can continue
02:02:54 directory for backup Exist ... can continue
In the 1st example the report is OK, but in the 2nd, my code tells me the same information twice... i just can't get my code to work properly..
Here is my code:
public void checkbackupfolders() {
do {
create_backup_folders();
} while (create_backup_folders() == false);
}
public bool create_backup_folders()
{
string path = "\\BACKUP\\" + Globals.hostname;
if (Directory.Exists(path))
{
consolecho("directory for backup Exist ... can continue");
return true;
}
else
{
consolecho("directory for backup DOESNT EXIST ... creating required folders...");
Directory.CreateDirectory("\\BACKUP\\" + Globals.hostname);
return false;
}
}
|
c# check->create->check folder loop
|
1
Why do not use the backup tools included in sql server (ms sql management studio)?
You can program periodic backups on the server (independently of the execution or not of your client program.
Yes, you can export to csv or other text format, but it is not the recommended way. What if you are in the middle of a transaction: do you should copy that data? or discard it?
If you program the backup from your client, you must think about the eventual restore process. Do you want write a restore program also? You should have in mind the restore order of the tables. What if you change the structure of your database in a future?
Conclusion: use standard processes to backup/restore your database unless you have a strong reason not to.
Share
Improve this answer
Follow
answered Jan 26, 2013 at 17:25
mnietomnieto
3,78444 gold badges2121 silver badges3838 bronze badges
1
sir so what can i do here which process i can use? i am totally blank what to use.
– shariq_khan
Jan 26, 2013 at 17:39
Add a comment
|
|
I am a newbie studying c# from last 3 months and I am using sql server as my database. I go to menu and create a service based database, and makes table there I am working on winform I have menu datagridview which shows the data in specified form. Now I want to know: can I make a database copy in particular folder or file? is it possible? I've heard that I can load csv file into datagriview. How can I make csv file, or something diffrent file like .mdf so that I can restore after accidentally deletes the data. Is there any other method?
I have got some hint from this but it is incomplete.
|
backup and restore the database
|
0
Check GCP Partner program.
Being a partner you will be able to extend your clients or diversify your portfolio and you will get access to training
https://cloud.google.com/partners/become-a-partner
Share
Improve this answer
Follow
answered Jun 3, 2021 at 20:16
julisiljulisil
4866 bronze badges
Add a comment
|
|
First time poster here, I'll make this as brief as I can.
I am looking for guidance in what I should be certifying in with regards to the GCP platform.
I currently have my own company and we sell managed firewalls. I am looking into provide cloud based services for my clientele and wish to use GCP.
Basically I need to be able to set up Virtual Machines, Virtual Datacentres, Cloud / Hybrid backup solutions and of course fully understand and certify within the Security aspects of a cloud environment - ie: keeping my / clients data secured and compliant.
GCP help centre is a little confusing for me and I would appreciate any direction you could give me as to where I need to start.
Please treat me as a beginner with this even though I have prior experience with in-house cloud solutions at my previous employer.
Any assistance would be greatly appreciated!
|
GCP & Security Certification Guidance
|
0
You can map the Azure file storage as a network drive on your desktop and then you can take a backup of files stored in Azure file storage for long-term retention.
Azure Backup for Files is in Limited Preview today. It enables you to take scheduled copies of yourFiles and can be managed from the Recovery Services Vault. If you are interested in signing up for this preview, you can drop in a mail with their subscription ID(s) to [email protected]
Share
Improve this answer
Follow
answered Dec 18, 2017 at 17:52
Vikranth SVikranth S
48155 silver badges1010 bronze badges
Add a comment
|
|
I have a physical server that holds documents customer orders in XML and their resultant orders PDF. The locations are mapped from the application server that generates them and the desktops that need to access them via drive mapping.
These files need to be kept for a number of years for regulatory purposes, the current file server needs expanding. So I was thinking that as this data will grow to about 5-8tb over time as the data needs to be held for approx 10 years, then it can be removed.
I could create a VM in Azure with the appropriate storage and then I presume to use MARS to create a backup strategy as if this was an onsight server. But to meet the disk sizing I need a large server as the processing of the server does not need to be very much its just storage.
So I would need to still be able to map the server and desktops to the drive where the files are stored
So I was wondering if anyone could suggest an approach. The data from the desktop would need to be available for the application to access for up to 18 months. So the old data could be archived but still needs to be backed up as retrieval of archive data would be via a manual search.
thanks in advance.
|
Azure Filestore & Backup
|
This question is very likely to be closed, but I'll give you a hand anyways. Dumping a mongo database is very easy. Look at the mongodump command. Once you have this, set up a cron job to execute it when you want (in this case, every 5 hours).
For some more information on setting up cron jobs, take a look here.
|
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have a MongoDB Data Base Having around 50 collections..
It Contain some master collection and some transaction collections.
I want to take backup of my database every 5 hour .. PLz suggest some solution to do that
|
How to Take MongoDB BackUp [closed]
|
Sorry to say this but it's really your own fault. Not only are you using an unsupported version of Joomla, but an old version in that series as well. The latest version of the Joomla 1.5 series is 1.5.26 so there should be no reason why you weren't using that.
I answered a question regarding being hacked and gave some advice along with recommended extensions to use. The guy was using Joomla 2.5 but it can still apply to Joomla 1.5.
Joomla! 2.5.4 Hacked: Having trouble with diagnosis
So remember, in future, keep up to date else it's to your detriment.
Update:
To upgrade from Joomla 1.5 to 2.5, install this extension. This will update the core Joomla stuff and database tables. Do bare in mind that it will not upgrade 3rd party extensions, therefore you will need to upload the 2.5 compatible versions yourself.
|
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
Hi some one hacked my joomla site,
I am not able to access to "administrator/index.php?option=com_config", it is giving 404 error.
The hacker is "hacked by s13doeL", he added "joomla.class.php and index.old.php" in all over the web files.
I think there is only one solution, reistall everything.
Could someone help to migrate from 1.5.18 to 1.5.20. I do not want to change to 2.5 because that template is not supported to 2.5.
Is it just enough copy all database and then link to it? Does it copy all old articles? or do I have to copy ann manualy?
|
How to migrate joomla 1.5.18 to 1.5.20 - hacked [closed]
|
To reduce the amount of space you use significantly, you'll need to reduce the number of copies you keep. This is the 2nd argument to the script. So if you run every 3 days, and want to keep a month of backups, change it to:
../rsyncsnapshot.sh daily 10
|
Currently on workplaces server we run a daily backup, due to size limits we need it to be only each third day (or something like that). We use Rsync to do the backup. What I'm thinking to do is to just change the run time of the script, so insted of daily it will run every third day.
So I want to know wether this is possible? My Concerns are that the size wont shrink because the backup will still do a "3-days backup" insted of just one day. It's hard to explain so I'll show it by exampel.
What I want:
Day 1 - Run Backup
Day 2
Day 3
Day 4 - Run Backup
Day 5
What I fear will happen:
Day 1 - Run Backup
Day 2 - Backup applied from Day 4
Day 3 - Backup applied from Day 4
Day 4 - Run Backup
Day 5
the crontab job looks like this:
5 7 * * * ../rsyncsnapshot.sh daily 30
the script looks like this
if [ $# != 2 ]; then
echo "Usage: backup.sh interval_name count"
exit 1
fi
NAME=$1
COUNT=$2
TIMESTAMP=`date -u "+%Y-%m-%d %H:%M:%S%z"`
echo "*** Backup started $TIMESTAMP (interval $NAME, count $COUNT) ***"
echo "Deleting $DEST_DIR/$NAME.$((COUNT-1))"
ssh $DEST_HOST rm -rf $DEST_DIR/$NAME.$(($COUNT-1))
for i in `seq $(($COUNT-1)) -1 2`;
do
j=$(($i-1))
echo "Moving $DEST_DIR/$NAME.$j to $DEST_DIR/$NAME.$i"
ssh $DEST_HOST mv $DEST_DIR/$NAME.$j $DEST_DIR/$NAME.$i
done
echo "Copying $DEST_DIR/$NAME.0 to $DEST_DIR/$NAME.1"
ssh $DEST_HOST cp -al $DEST_DIR/$NAME.0 $DEST_DIR/$NAME.1
echo "Copying source ($SRC) to $DEST_HOST:$DEST_DIR/$NAME.0/"
rsync $RSYNC_ARGS $SRC $DEST_HOST:$DEST_DIR/${NAME}.0/
ssh $DEST_HOST touch $DEST_DIR/$NAME.0
TIMESTAMP=`date -u "+%Y-%m-%d %H:%M:%S%z"`
echo "*** Backup ended $TIMESTAMP ***"
echo "Quota as follows:"
ssh $DEST_HOST quota
|
Ubuntu Cronjob with rsync
|
Your quotation marks around the command string are wrong.
|
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
Minor problem with following code:
<?php echo exec(‘cd /home/username/backup/files; tar -cvpzf `date +%y-%m-%d_%H-%M`.tar /home/username/public_html’); ?>
Error I am getting is:
Parse error: syntax error, unexpected ';' on line 1
Code above is line 1, would be nice to find a solution.
Thanks in advance for time and effort.
|
Getting a Parse error: syntax error, unexpected ';' [closed]
|
No.
From the cron man page:
...cron will then examine the modification time on all crontabs
and reload those which have changed. Thus cron need not be restarted
whenever a crontab file is modified
But if you just want to make sure its done anyway,
sudo service cron reload
or
/etc/init.d/cron reload
|
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
Do I have to restart cron after changing the crontable file?
|
Restarting cron after changing crontab file? [closed]
|
You can add to the crontab as follows:
#write out current crontab
crontab -l > mycron
#echo new cron into cron file
echo "00 09 * * 1-5 echo hello" >> mycron
#install new cron file
crontab mycron
rm mycron
Cron line explaination
* * * * * "command to be executed"
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)
Source nixCraft.
|
Does crontab have an argument for creating cron jobs without using the editor (crontab -e)? If so, what would be the code to create a cron job from a Bash script?
|
How to create a cron job using Bash automatically without the interactive editor?
|
Create a .pgpass file in the home directory of the account that pg_dump will run as.
The format is:
hostname:port:database:username:password
Then, set the file's mode to 0600. Otherwise, it will be ignored.
chmod 600 ~/.pgpass
See the Postgresql documentation libpq-pgpass for more details.
|
I'm trying to create a cronjob to back up my database every night before something catastrophic happens. It looks like this command should meet my needs:
0 3 * * * pg_dump dbname | gzip > ~/backup/db/$(date +%Y-%m-%d).psql.gz
Except after running that, it expects me to type in a password. I can't do that if I run it from cron. How can I pass one in automatically?
|
How to pass in password to pg_dump?
|
If you're looking for something lightweight checkout schedule:
import schedule
import time
def job():
print("I'm working...")
schedule.every(10).minutes.do(job)
schedule.every().hour.do(job)
schedule.every().day.at("10:30").do(job)
while 1:
schedule.run_pending()
time.sleep(1)
Disclosure: I'm the author of that library.
|
I'm looking for a library in Python which will provide at and cron like functionality.
I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.
For those unfamiliar with cron: you can schedule tasks based upon an expression like:
0 2 * * 7 /usr/bin/run-backup # run the backups at 0200 on Every Sunday
0 9-17/2 * * 1-5 /usr/bin/purge-temps # run the purge temps command, every 2 hours between 9am and 5pm on Mondays to Fridays.
The cron time expression syntax is less important, but I would like to have something with this sort of flexibility.
If there isn't something that does this for me out-the-box, any suggestions for the building blocks to make something like this would be gratefully received.
Edit
I'm not interested in launching processes, just "jobs" also written in Python - python functions. By necessity I think this would be a different thread, but not in a different process.
To this end, I'm looking for the expressivity of the cron time expression, but in Python.
Cron has been around for years, but I'm trying to be as portable as possible. I cannot rely on its presence.
|
How do I get a Cron like scheduler in Python?
|
crontab -e
add:
30 2 * * * /your/command
|
How to configure a cron job to run every night at 2:30? I know how to make it run at 2, but not 2:30.
|
Running a cron job at 2:30 AM everyday
|
By setting the schedule period to 15 13 * * * you tell Jenkins to schedule the build every day of every month of every year at the 15th minute of the 13th hour of the day.
Jenkins used a cron expression, and the different fields are:
MINUTES Minutes in one hour (0-59)
HOURS Hours in one day (0-23)
DAYMONTH Day in a month (1-31)
MONTH Month in a year (1-12)
DAYWEEK Day of the week (0-7) where 0 and 7 are sunday
If you want to schedule your build every 5 minutes, this will do the job : */5 * * * *
If you want to schedule your build every day at 8h00, this will do the job : 0 8 * * *
For the past few versions (2014), Jenkins have a new parameter, H (extract from the Jenkins code documentation):
To allow periodically scheduled tasks to produce even load on the system, the symbol H (for “hash”) should be used wherever possible.
For example, using 0 0 * * * for a dozen daily jobs will cause a large spike at midnight. In contrast, using H H * * * would still execute each job once a day, but not all at the same time, better using limited resources.
Note also that:
The H symbol can be thought of as a random value over a range, but it actually is a hash of the job name, not a random function, so that the value remains stable for any given project.
More example of using 'H'
|
I added a new job in Jenkins, which I want to schedule periodically.
From Configure job, I am checking the "Build Periodically" checkbox and in the Schedule text field added the expression:
15 13 * * *
But it does not run at the scheduled time.
Is it the correct procedure to schedule a job?
The job should run at 4:20 AM, but it is not running.
|
How do I schedule jobs in Jenkins?
|
To run a task every 20 minutes starting at 5 past the hour, try this:
5-59/20 * * * *
Explanation
An * in the minute field is the same as 0-59/1 where 0-59 is the range and 1 is the step. The command will run at the first minute in the range (0), then at all successive minutes that are distant from the first by step (1), until the last (59).
Which is why */20 * * * * will run at 0 minutes, 20 minutes after, and 40 minutes after -- which is the same as every 20 minutes. However, */25 * * * * will run at 0 minutes, 25 minutes after, and 50 minutes after -- which is not the same as every 25 minutes. That's why it's usually desirable to use a step value in the minute field that divides evenly into 60.
So to offset the start time, specify the range explicitly and set the first value to the amount of the offset.
Examples
5-59/20 * * * * will run at 5 minutes after, 25 minutes after, and 45 minutes after.
10-59/25 * * * * will run at 10 minutes after and 35 minutes after.
1-59/2 * * * * will run every odd minute.
|
*/20 * * * *
Ensures it runs every 20 minutes, I'd like to run a task every 20 minutes, starting at 5 past the hour, is this possible with Cron? Would it be:
5/20 * * * * ?
|
Run Cron job every N minutes plus offset
|
Here is an explanation of the crontab format.
# 1. Entry: Minute when the process will be started [0-60]
# 2. Entry: Hour when the process will be started [0-23]
# 3. Entry: Day of the month when the process will be started [1-28/29/30/31]
# 4. Entry: Month of the year when the process will be started [1-12]
# 5. Entry: Weekday when the process will be started [0-6] [0 is Sunday]
#
# all x min = */x
So according to this your 5 8 * * 0 would run 8:05 every Sunday.
|
I'm trying to figure out how to run a crontab job every week on Sunday. I think the following should work, but I'm not sure if I understand correctly. Is the following correct?
5 8 * * 6
|
How to run crontab job every week on Sunday
|
You should be able to do this by using the python in your virtual environment:
/home/my/virtual/bin/python /home/my/project/manage.py command arg
EDIT: If your django project isn't in the PYTHONPATH, then you'll need to switch to the right directory:
cd /home/my/project && /home/my/virtual/bin/python ...
You can also try to log the failure from cron:
cd /home/my/project && /home/my/virtual/bin/python /home/my/project/manage.py > /tmp/cronlog.txt 2>&1
Another thing to try is to make the same change in your manage.py script at the very top:
#!/home/my/virtual/bin/python
|
I am trying to run a Django management command from cron. I am using virtualenv to keep my project sandboxed.
I have seen examples here and elsewhere that show running management commands from within virtualenv's like:
0 3 * * * source /home/user/project/env/bin/activate && /home/user/project/manage.py command arg
However, even though syslog shows an entry when the task should have started, this task never actually runs (the log file for the script is empty). If I run the line manually from the shell, it works as expected.
The only way I can currently get the command to run via cron, is to break the commands up and put them in a dumb bash wrapper script:
#!/bin/sh
source /home/user/project/env/bin/activate
cd /home/user/project/
./manage.py command arg
EDIT:
ars came up with a working combination of commands:
0 3 * * * cd /home/user/project && /home/user/project/env/bin/python /home/user/project/manage.py command arg
At least in my case, invoking the activate script for the virtualenv did nothing. This works, so on with the show.
|
Cron and virtualenv
|
every minute:
* * * * * /path/to/php /var/www/html/a.php
every 24hours (every midnight):
0 0 * * * /path/to/php /var/www/html/reset.php
See this reference for how crontab works: http://adminschoice.com/crontab-quick-reference, and this handy tool to build cron jobx: http://www.htmlbasix.com/crontab.shtml
|
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 10 years ago.
Improve this question
I need a crontab syntax which should execute a specific PHP script /var/www/html/a.php every minute. The execution on every minute must start at 00:00. The other task which must execute a script at 00:00 /var/www/html/reset.php (once every 24 hours).
|
Using crontab to execute script every minute and another every 24 hours [closed]
|
* * * * * myjob.sh >> /var/log/myjob.log 2>&1
will log all output from the cron job to /var/log/myjob.log
You might use mail to send emails. Most systems will send unhandled cron job output by email to root or the corresponding user.
|
I want to know how I can see exactly what the cron jobs are doing on each execution. Where are the log files located? Or can I send the output to my email? I have set the email address to send the log when the cron job runs but I haven't received anything yet.
|
How to log cron jobs?
|
I'm using the rake approach (as supported by heroku)
With a file called lib/tasks/cron.rake ..
task :cron => :environment do
puts "Pulling new requests..."
EdiListener.process_new_messages
puts "done."
end
To execute from the command line, this is just "rake cron". This command can then be put on the operating system cron/task scheduler as desired.
Update this is quite an old question and answer! Some new info:
the heroku cron service I referenced has since been replaced by Heroku Scheduler
for frequent tasks (esp. where you want to avoid the Rails environment startup cost) my preferred approach is to use system cron to call a script that will either (a) poke a secure/private webhook API to invoke the required task in the background or (b) directly enqueue a task on your queuing system of choice
|
What's the best way to run scheduled tasks in a Rails environment? Script/runner? Rake? I would like to run the task every few minutes.
|
A cron job for rails: best practices?
|
For newer Microsoft OS versions, Windows Server 2012 / Windows 8, look at the schtasks command line utility.
If using PowerShell, the Scheduled Tasks Cmdlets in Windows PowerShell are made for scripting.
For command-line usage before Windows 8, you can schedule with the AT command.
For the original question, asking about Windows XP (and Windows 7): Windows Task Scheduler
|
Closed. This question is seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. It does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
A Google search turned up software that performs the same functions as cron, but nothing built into Windows.
I'm running Windows XP Professional, but advice for any version of Windows would be potentially helpful to someone.
Is there also a way to invoke this feature (which based on answers is called the Task Scheduler) programatically or via the command line?
|
What is the Windows version of cron? [closed]
|
461
Just do:
0 */2 * * * /home/username/test.sh
The 0 at the beginning means to run at the 0th minute. (If it were an *, the script would run every minute during every second hour.)
Don't forget, you can check syslog to see if it ever actually ran!
Share
Improve this answer
Follow
edited Jul 14, 2018 at 14:09
Mark Amery
148k8686 gold badges412412 silver badges463463 bronze badges
answered Feb 24, 2012 at 22:48
AdamAdam
4,73111 gold badge1414 silver badges22 bronze badges
3
@ernest-conill How can you tell? the revisions history does not contain a version which includes different code: stackoverflow.com/posts/6423532/revisions
– tutuDajuju
Aug 31, 2014 at 11:55
As I understand the cron syntax, this answer is not quite correct. You were asked for an execution every two hours, your argument fulfils this requirement in principle, but it depends on the minute of the hour. Your argument is executed at 00:00, 02:00, 04:00, 06:00 and so on. If the server is restarted at 03:58 and takes until 04:02, the execution at 04:00 is omitted. In my opinion, it would be better to use */120 * * * * *
– MaxWeb
Feb 9, 2023 at 12:13
I was probably a bit hasty here :D */120 is not a valid option. However, the original statement remains the same. 0 */2 * * can cause an execution to be skipped. However, I probably don't have an alternative after all, unfortunately.
– MaxWeb
Feb 9, 2023 at 12:47
Add a comment
|
|
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
How can I write a Crontab that will run my /home/username/test.sh script every 2 hours?
|
How to run cron job every 2 hours? [closed]
|
0 and 7 both stand for Sunday, you can use the one you want, so writing 0-6 or 1-7 has the same result.
Also, as suggested by @Henrik, it is possible to replace numbers by shortened name of days, such as MON, THU, etc:
0 - Sun Sunday
1 - Mon Monday
2 - Tue Tuesday
3 - Wed Wednesday
4 - Thu Thursday
5 - Fri Friday
6 - Sat Saturday
7 - Sun Sunday
Graphically, * * * * * command to be executed stands for:
minute
hour
day of month
month
day of week
(0-59)
(0-23)
(1-31)
(1-12)
(1-7)
*
*
*
*
*
command to be executed
Or using the old style:
┌────────── minute (0 - 59)
│ ┌──────── hour (0 - 23)
│ │ ┌────── day of month (1 - 31)
│ │ │ ┌──── month (1 - 12)
│ │ │ │ ┌── day of week (0 - 6 => Sunday - Saturday, or
│ │ │ │ │ 1 - 7 => Monday - Sunday)
↓ ↓ ↓ ↓ ↓
* * * * * command to be executed
Finally, if you want to specify day by day, you can separate days with commas, for example SUN,MON,THU will exectute the command only on sundays, mondays on thursdays.
You can read further details in Wikipedia's article about Cron and check a cron expression online with crontab.guru.
|
In crontab does the Day of the Week field run from 0 - 6 or 1 -7?
I am seeing conflicting information on this. wikipedia states 0-6 and other sites I have seen are 1-7.
Also what would be the implication or either using 0 or 7 incorrectly? i.e. would the cron still run?
|
Crontab Day of the Week syntax
|
Add this to your crontab (temporarily):
* * * * * env > ~/cronenv
After it runs, do this:
env - `cat ~/cronenv` /bin/sh
This assumes that your cron runs /bin/sh, which is the default regardless of the user's default shell.
Footnote: if env contains more advanced config, eg PS1=$(__git_ps1 " (%s)")$, it will error cryptically env: ": No such file or directory.
|
I normally have several problems with how cron executes scripts as they normally don't have my environment setup. Is there a way to invoke bash(?) in the same way cron does so I could test scripts before installing them?
|
How to simulate the environment cron executes a script with?
|
Do:
0,30 * * * * your_command
|
I'm looking to add a crontab entry to execute a script every 30 minutes, on the hour and 30 minutes past the hour or something close. I have the following, but it doesn't seem to run on 0.
*/30 * * * *
What string do I need to use?
The cron is running on OSX.
|
How would I get a cron job to run every 30 minutes?
|
Just do what cron does, run the following as root:
run-parts -v /etc/cron.weekly
... or the next one if you receive the "Not a directory: -v" error:
run-parts /etc/cron.weekly -v
Option -v prints the script names before they are run.
|
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
I have a #!/bin/bash file in cron.week directory.
Is there a way to test if it works? Can't wait 1 week
I am on Debian 6 with root
|
Test a weekly cron job [closed]
|
All jobs are executed by a shell, so start that shell snippet by a command to change the directory.
cd /path/to/directory && ./bin/myapp
Concerning the use of && instead of ;: normally it doesn't make a difference, but if the cd command fails (e.g. because the directory doesn't exist) with && the application isn't executed, whereas with ; it's executed (but not in the intended directory).
|
I would like to set a job to run daily in the root crontab. But I would like it to execute it from a particular directory so it can find all the files it needs, since the application has a bunch of relative paths.
Anyway, can I tell crontab to run from a particular directory?
|
Crontab - Run in directory
|
It's running every minute of the hour 22 I guess. Try the following to run it every first minute of the hour 22:
0 22 * * * ....
|
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I had entered:
* 22 * * * test > /dev/null
However, I am being notified via email that this is running every minute.
I am confused I guess because I thought this was correct for what I am wanting.
|
How to run cron once, daily at 10pm [closed]
|
Cron jobs usually are stored in a per-user file under /var/spool/cron
The simplest thing for you to do is probably just create a text file with the job configured, then copy it to the cron spool folder and make sure it has the right permissions (600).
|
I need to add a cron job thru a script I run to set up a server. I am currently using Ubuntu. I can use crontab -e but that will open an editor to edit the current crontab. I want to do this programmatically.
Is it possible to do so?
|
How do I create a crontab through a script
|
Instead of creating a crontab to run as the root user, create a crontab for the user that you want to run the script. In your case, crontab -u www-data -e will edit the crontab for the www-data user. Just put your full command in there and remove it from the root user's crontab.
|
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I have few crontab jobs that run under root, but that gives me some problems. For example all folders created in process of that cron job are under user root and group root.
How can i make it to run under user www-data and group www-data so when i run scripts from my website i can manipulate those folders and files?
My server runs on Ubuntu.
Current crontab job is:
*/1 * * * * php5 /var/www/web/includes/crontab/queue_process.php >> /var/www/web/includes/crontab/queue.log 2>&1
|
How to specify in crontab by what user to run script? [closed]
|
142
This can happen if curl is asked to do plain HTTP on a server that does HTTPS.
Example:
$ curl http://google.com:443
curl: (52) Empty reply from server
Share
Improve this answer
Follow
answered Mar 16, 2017 at 14:57
Benoit DuffezBenoit Duffez
12.1k1212 gold badges7777 silver badges126126 bronze badges
4
21
This was the situation in my case. curl localhost:8443 gave me the empty reply error. curl -k https://localhost:8443 served the page properly.
– lowly_junior_sysadmin
Nov 1, 2017 at 23:34
2
I've just stumbled over this and I missed the missing s completely. I wonder why there isn't a more clear error (even like connection refused: it would make more sense).
– ShinTakezou
Oct 4, 2018 at 10:19
1
In my case a VPN service cutted off the response.
– Alex Szücs
Jan 11, 2022 at 16:38
In my case, this happened because the value of server-side WriteTimeout was too short. Increasing the value from 1 second to 5 seconds solved the problem.
– ynn
Mar 20, 2023 at 11:32
Add a comment
|
|
I have a cron job setup on one server to run a backup script in PHP that is hosted on another server.
The command I've been using is
curl -sS http://www.example.com/backup.php
Lately I've been getting this error when the Cron runs:
curl: (52) Empty reply from server
If I go to the link directly in my browser the script runs fine and I get my little backup ZIP file.
|
What is the curl error 52 "empty reply from server"?
|
I do this for a print spooler program that I wrote, it's just a shell script:
#!/bin/sh
if ps -ef | grep -v grep | grep doctype.php ; then
exit 0
else
/home/user/bin/doctype.php >> /home/user/bin/spooler.log &
#mailing program
/home/user/bin/simplemail.php "Print spooler was not running... Restarted."
exit 0
fi
It runs every two minutes and is quite effective. I have it email me with special information if for some reason the process is not running.
|
I'm trying to set up a cron job as a sort of watchdog for a daemon that I've created. If the daemon errors out and fails, I want the cron job to periodically restart it... I'm not sure how possible this is, but I read through a couple of cron tutorials and couldn't find anything that would do what I'm looking for...
My daemon gets started from a shell script, so I'm really just looking for a way to run a cron job ONLY if the previous run of that job isn't still running.
I found this post, which did provide a solution for what I'm trying to do using lock files, not I'm not sure if there is a better way to do it...
|
Run cron job only if it isn't already running
|
I used /etc/crontab. I used vi and entered in the PATHs I needed into this file and ran it as root. The normal crontab overwrites PATHs that you have set up. A good tutorial on how to do this.
The systemwide cron file looks like this:
This has the username field, as used by /etc/crontab.
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file.
# This file also has a username field, that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
42 6 * * * root run-parts --report /etc/cron.daily
47 6 * * 7 root run-parts --report /etc/cron.weekly
52 6 1 * * root run-parts --report /etc/cron.monthly
01 01 * * 1-5 root python /path/to/file.py
|
I'm trying to get cron to call in the correct PATHs. When I run a Python script from shell the script runs fine as it uses the PATHs set in bashrc but when I use cron all the PATHs are not used from bashrc. Is there a file I can enter the PATHs into for cron like bashrc or a way to call the PATHs from bashrc?
Sorry I don't think I worded this correctly, I can get the correct script to run (meaning the PATH to the script in crontab is not the problem here), it's just when that script is running I run a build and this uses the PATHs set in .bashrc. When I run the script when I'm logged in, the .bashrc PATHs are pulled in. Since cron doesn't run in a shell per say it does not pull in .bashrc. Is there a way of pulling this in without having to write a bash script wrapper?
|
How to get CRON to call in the correct PATHs
|
You can now set history limits, or disable history altogether, so that failed or successful CronJobs are not kept around indefinitely. See my answer here. Documentation is here.
To set the history limits:
The .spec.successfulJobsHistoryLimit and .spec.failedJobsHistoryLimit fields are optional. These fields specify how many completed and failed jobs should be kept. By default, they are set to 3 and 1 respectively. Setting a limit to 0 corresponds to keeping none of the corresponding kind of jobs after they finish.
The config with 0 limits would look like:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
successfulJobsHistoryLimit: 0
failedJobsHistoryLimit: 0
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
args:
- /bin/sh
- -c
- date; echo Hello from the Kubernetes cluster
restartPolicy: OnFailure
|
Is there a way to automatically remove completed Jobs besides making a CronJob to clean up completed Jobs?
The K8s Job Documentation states that the intended behavior of completed Jobs is for them to remain in a completed state until manually deleted. Because I am running thousands of Jobs a day via CronJobs and I don't want to keep completed Jobs around.
|
How to automatically remove completed Kubernetes Jobs created by a CronJob?
|
Here's a good tutorial on what crontab is and how to use it on Ubuntu. Your crontab line will look something like this:
00 00 * * * ruby path/to/your/script.rb
(00 00 indicates midnight--0 minutes and 0 hours--and the *s mean every day of every month.)
Syntax:
mm hh dd mt wd command
mm minute 0-59
hh hour 0-23
dd day of month 1-31
mt month 1-12
wd day of week 0-7 (Sunday = 0 or 7)
command: what you want to run
all numeric values can be replaced by * which means all
|
I have heard crontab is a good choice, but how do I write the line and where do I put it on the server?
|
How to write a cron that will run a script every day at midnight?
|
Run nohup python bgservice.py & to get the script to ignore the hangup signal and keep running. Output will be put in nohup.out.
Ideally, you'd run your script with something like supervise so that it can be restarted if (when) it dies.
|
I have Python script bgservice.py and I want it to run all the time, because it is part of the web service I build. How can I make it run continuously even after I logout SSH?
|
How to run a script in the background even after I logout SSH?
|
You can use BackgroundScheduler() from APScheduler package (v3.5.3):
import time
import atexit
from apscheduler.schedulers.background import BackgroundScheduler
def print_date_time():
print(time.strftime("%A, %d. %B %Y %I:%M:%S %p"))
scheduler = BackgroundScheduler()
scheduler.add_job(func=print_date_time, trigger="interval", seconds=60)
scheduler.start()
# Shut down the scheduler when exiting the app
atexit.register(lambda: scheduler.shutdown())
Note that two of these schedulers will be launched when Flask is in debug mode. For more information, check out this question.
|
I have a Flask web hosting with no access to cron command.
How can I execute some Python function every hour?
|
How to schedule a function to run every hour on Flask?
|
The best way if you're running as root, is to drop a file into /etc/cron.d
if you use a package manager to package your software, you can simply lay down files in that directory and they are interpreted as if they were crontabs, but with an extra field for the username, e.g.:
Filename: /etc/cron.d/per_minute
Content:
* * * * * root /bin/sh /home/root/script.sh
|
I want to be able to programatically add a new cron job, what is the best way to do this?
From my research, it seems I could dump the current crontab and then append a new one, piping that back into crontab:
(crontab -l ; echo "0 * * * * wget -O - -q http://www.example.com/cron.php") | crontab -
Is there a better way?
|
How can I programmatically create a new cron job?
|
You forgot a *, and you've too many fields. It's the hour you need to care about
0 */6 * * * /path/to/mycommand
This means every sixth hour starting from 0, i.e. at hour 0, 6, 12 and 18 which you could write as
0 0,6,12,18 * * * /path/to/mycommand
|
How can I run command every six hours every day?
I tried the following, but it did not work:
/6 * * * * * mycommand
|
Running a cron job on Linux every six hours
|
If I understand what you're looking for, you'll need to do something a bit messy, like having a cron job that runs a bash script that randomizes the run times... Something like this:
crontab:
0 9 * * * /path/to/bashscript
and in /path/to/bashscript:
#!/bin/bash
maxdelay=$((14*60)) # 14 hours from 9am to 11pm, converted to minutes
for ((i=1; i<=20; i++)); do
delay=$(($RANDOM%maxdelay)) # pick an independent random delay for each of the 20 runs
(sleep $((delay*60)); /path/to/phpscript.php) & # background a subshell to wait, then run the php script
done
A few notes: this approach it a little wasteful of resources, as it fires off 20 background processes at 9am, each of which waits around for a random number of minutes (up to 14 hours, i.e. 11pm), then launches the php script and exits. Also, since it uses a random number of minutes (not seconds), the start times aren't quite as random as they could be. But $RANDOM only goes up to 32,767, and there are 50,400 seconds between 9am and 11pm, it'd be a little more complicated to randomize the seconds as well. Finally, since the start times are random and independent of each other, it's possible (but not very likely) that two or more instances of the script will be started simultaneously.
|
I need the ability to run a PHP script 20 times a day at completely random times. I also want it to run only between 9am - 11pm.
I'm familiar with creating cron jobs in linux.
|
Cron jobs and random times, within given hours
|
I would recommend node-cron. It allows to run tasks using Cron patterns e.g.
'* * * * * *' - runs every second
'*/5 * * * * *' - runs every 5 seconds
'10,20,30 * * * * *' - run at 10th, 20th and 30th second of every minute
'0 * * * * *' - runs every minute
'0 0 * * * *' - runs every hour (at 0 minutes and 0 seconds)
But also more complex schedules e.g.
'00 30 11 * * 1-5' - Runs every weekday (Monday through Friday) at 11:30:00 AM. It does not run on Saturday or Sunday.
Sample code: running job every 10 minutes:
var cron = require('cron');
var cronJob = cron.job("0 */10 * * * *", function(){
// perform operation e.g. GET request http.get() etc.
console.info('cron job completed');
});
cronJob.start();
You can find more examples in node-cron wiki
More on cron configuration can be found on cron wiki
I've been using that library in many projects and it does the job. I hope that will help.
|
Closed. This question is seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. It does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I am looking for a node job schedule that will allow me to schedule a number of tasks at different intervals. For instance,
call function A every 30 seconds
call function B every 60 seconds
call function C every 7 days
I also want to be able to start and stop the process.
So far, I have looked at:
later - the syntax confuses me, also apparently you cant schedule tasks beyond a month
agenda- seems the most promising, however I'm confused about the database functionality
timeplan - too simple, can't start and stop
I find the syntax of the latter confusing.
|
I need a Nodejs scheduler that allows for tasks at different intervals [closed]
|
Run it every three days - or less at the end of the month. (It'll run 2 days in a row if the previous month had 31 days.)
0 0 */3 * *
How about that?
If you want it to run on specific days of the month, like the 1st, 4th, 7th, etc... then you can just have a conditional in your script that checks for the current day of the month.
if (((date('j') - 1) % 3))
exit();
or, as @mario points out, you can use date('k') to get the day of the year instead of doing it based on the day of the month.
|
Is it possible to run a cronjob every three days? Or maybe 10 times/month.
|
Cron job every three days
|
246
If you want to suspend cronjob via patch, use:
kubectl patch cronjobs <job-name> -p '{"spec" : {"suspend" : true }}'
Share
Improve this answer
Follow
edited Mar 1, 2023 at 14:17
aymericbeaumet
7,07222 gold badges3838 silver badges5050 bronze badges
answered Mar 10, 2019 at 17:04
AmityoAmityo
5,95344 gold badges2222 silver badges2929 bronze badges
8
3
I am trying to suspend using above command but getting error error: unable to parse "'{spec": yaml: found unexpected end of stream
– lazydeveloper
Aug 5, 2019 at 14:48
6
kubectl patch cronjobs <job-name> -p '{\"spec\" : {\"suspend\" : true }}'
– idubnori
Jan 22, 2020 at 4:37
@Zhongxia Zhou patch with suspend false
– Amityo
Jun 15, 2020 at 17:52
8
To suspend all the cronjobs at one go kubectl get cronjobs | grep False | cut -d' ' -f 1 | xargs kubectl patch cronjobs -p '{"spec" : {"suspend" : true }}'
– Subbu
Sep 10, 2020 at 9:39
I can't make it work. I get the following error: "error: unable to parse "'{\"spec\"": yaml: found unexpected end of stream". Am I supposed to change this command in some way (apart from replacing <job-name> with the name of the cronjob)?
– edn
Dec 27, 2021 at 21:35
|
Show 3 more comments
|
I have scheduled an application to run as a CronJob in Kubernetes. When there is a code change, I'm also changing the image of the CronJob.
I'm looking for an option where I can disable the currently running CronJob and deploy a new CronJob with the latest image version.
How can I disable a CronJob in Kubernetes without deleting its Deployment?
|
Disabling cronjob in Kubernetes
|
112
The windows equivalent to a cron job is a scheduled task.
A scheduled task can be created as described by Alex and Rudu, but it can also be done command line with schtasks (if you for instance need to script it or add it to version control).
An example:
schtasks /create /tn calculate /tr calc /sc weekly /d MON /st 06:05 /ru "System"
Creates the task calculate, which starts the calculator(calc) every monday at 6:05 (should you ever need that.)
All available commands can be found here: http://technet.microsoft.com/en-us/library/cc772785%28WS.10%29.aspx
It works on windows server 2008 as well as windows server 2003.
Share
Improve this answer
Follow
edited Jul 5, 2018 at 6:21
Gaurang Tandon
6,5781111 gold badges4747 silver badges8787 bronze badges
answered Aug 25, 2011 at 18:57
steenhulthinsteenhulthin
4,71355 gold badges3434 silver badges5252 bronze badges
2
2
thanks for your answer. Any way to see the currently active tasks on the terminal?
– gberth
Dec 24, 2020 at 16:52
1
I love this! Thanks for putting it up here. @gberth schtasks /query shows all of them. The documentation shows many more options.
– Casivio
Oct 28, 2021 at 21:41
Add a comment
|
|
I have to download a file from an SFTP server everyday. I have the program which retrieves the file from the server but I was thinking of setting up a cron job (or anything similar) to automate that. We are a Windows shop and need to set up the cron job in Windows.
|
Setting up a cron job in Windows
|
147
If you're still looking for something robust even in the far future, try https://stackoverflow.com/a/13938099/1601531, where I suggest the use of February 31st in crontab entries which are never intended to execute.
0 0 5 31 2 ?
Share
Improve this answer
Follow
edited May 23, 2017 at 10:30
CommunityBot
111 silver badge
answered Dec 18, 2012 at 17:16
Eric TjossemEric Tjossem
2,61611 gold badge1515 silver badges1818 bronze badges
9
7
on spring boot's cron interpreter this causes Invalid cron expression "0 0 5 31 2 *" led to runaway search for next trigger
– nurettin
Dec 13, 2018 at 13:06
2
did not work for me but 29 Feb worked "0 0 0 29 2 ?"
– vsingh
Mar 5, 2019 at 16:38
81
You do know that 29 February will execute some years, right?
– Magnus H
Aug 5, 2019 at 11:30
16
Using spring boot, you can disable cron jobs with a dash "-" , stackoverflow.com/questions/36403671/…
– Lubco
Feb 3, 2020 at 8:37
5
Microsoft.Azure.WebJobs.Extensions: The schedule expression '0 0 5 31 2 ?' was not recognized as a valid cron expression or timespan string.
– Ruslan
Nov 13, 2020 at 10:57
|
Show 4 more comments
|
Is there any way to create a cron expression for not running the job at all?
I though of using this expression :
0 0 0 1 1 ? 3099
...which will practically do the job as it will run on year 3099, but is there a cleaner way to do it?
|
A cron job that will never execute
|
In a crontab file, the fields are:
minute of the hour.
hour of the day.
day of the month.
month of the year.
day of the week.
So:
10 * * * * blah
means execute blah at 10 minutes past every hour.
If you want every five minutes, use either:
*/5 * * * * blah
meaning every minute but only every fifth one, or:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * blah
for older cron executables that don't understand the */x notation.
If it still seems to be not working after that, change the command to something like:
date >>/tmp/debug_cron_pax.txt
and monitor that file to ensure something's being written every five minutes. If so, there's something wrong with your PHP scripts. If not, there's something wrong with your cron daemon.
|
I'm running a PHP script in a cronjob and I want to send emails every 5 minutes
My current (crontab) cronjob:
10 * * * * /usr/bin/php /mydomain.in/cromail.php > /dev/null 2>&1
The cronmail.php is as follows:
<?php
$from = 'D'; // sender
$subject = 'S';
$message = 'M';
$message = wordwrap($message, 70);
mail("[email protected]", $subject, $message, "From: $from\n");
?>
But I've not received an email in 30 minutes with this configuration.
|
How to run a cronjob every X minutes?
|
crontab command usage
usage: crontab [-u user] file
crontab [-u user] [ -e | -l | -r ]
(default operation is replace, per 1003.2)
-e (edit user's crontab)
-l (list user's crontab)
-r (delete user's crontab)
-i (prompt before deleting user's crontab)
So,
$output = shell_exec('crontab -l');
file_put_contents('/tmp/crontab.txt', $output.'* * * * * NEW_CRON'.PHP_EOL);
echo exec('crontab /tmp/crontab.txt');
The above can be used for both create and edit/append provided the user has the adequate file write permission.
To delete jobs:
echo exec('crontab -r');
Also, take note that apache is running as a particular user and that's usually not root, which means the cron jobs can only be changed for the apache user unless given crontab -u privilege to the apache user.
|
Is it possible to use PHP to create, edit and delete crontab jobs?
I know how to list the current crontab jobs of the Apache user:
$output = shell_exec('crontab -l');
echo $output;
But how to add a cron job with PHP? 'crontab -e' would just open a text editor and you will have to manually edit the entries before saving the file.
And how to delete a cron job with PHP? Again you have to manually do this by 'crontab -e'.
With a job string like this:
$job = '0 */2 * * * /usr/bin/php5 /home/user1/work.php';
How do I add it to the crontab jobs list with PHP?
|
Use PHP to create, edit and delete crontab jobs?
|
First the mysqldump command is executed and the output generated is redirected using the pipe. The pipe is sending the standard output into the gzip command as standard input. Following the filename.gz, is the output redirection operator (>) which is going to continue redirecting the data until the last filename, which is where the data will be saved.
For example, this command will dump the database and run it through gzip and the data will finally land in three.gz
mysqldump -u user -pupasswd my-database | gzip > one.gz > two.gz > three.gz
$> ls -l
-rw-r--r-- 1 uname grp 0 Mar 9 00:37 one.gz
-rw-r--r-- 1 uname grp 1246 Mar 9 00:37 three.gz
-rw-r--r-- 1 uname grp 0 Mar 9 00:37 two.gz
My original answer is an example of redirecting the database dump to many compressed files (without double compressing). (Since I scanned the question and seriously missed - sorry about that)
This is an example of recompressing files:
mysqldump -u user -pupasswd my-database | gzip -c > one.gz; gzip -c one.gz > two.gz; gzip -c two.gz > three.gz
$> ls -l
-rw-r--r-- 1 uname grp 1246 Mar 9 00:44 one.gz
-rw-r--r-- 1 uname grp 1306 Mar 9 00:44 three.gz
-rw-r--r-- 1 uname grp 1276 Mar 9 00:44 two.gz
This is a good resource explaining I/O redirection: http://www.codecoffee.com/tipsforlinux/articles2/042.html
|
I am having problems with getting a crontab to work. I want to automate a MySQL database backup.
The setup:
Debian GNU/Linux 7.3 (wheezy)
MySQL Server version: 5.5.33-0+wheezy1(Debian)
directories user, backup and backup2 have 755 permission
The user names for MySQL db and Debian account are the same
From the shell this command works
mysqldump -u user -p[user_password] [database_name] | gzip > dumpfilename.sql.gz
When I place this in a crontab using crontab -e
* * /usr/bin/mysqldump -u user -pupasswd mydatabase | gzip> /home/user/backup/mydatabase-backup-`date +\%m\%d_\%Y`.sql.gz >/dev/null 2>&1
A file is created every minute in /home/user/backup directory, but has 0 bytes.
However when I redirect this output to a second directory, backup2, I note that the proper mysqldumpfile duly compressed is created in it. I am unable to figure what is the mistake that I am making that results in a 0 byte file in the first directory and the expected output in the second directory.
* * /usr/bin/mysqldump -u user -pupasswd my-database | gzip> /home/user/backup/mydatabase-backup-`date +\%m\%d_\%Y`.sql.gz >/home/user/backup2/mydatabase-backup-`date +\%m\%d_\%Y`.sql.gz 2>&1
I would greatly appreciate an explanation.
Thanks
|
mysqldump & gzip commands to properly create a compressed file of a MySQL database using crontab
|
Finally I found the solution. Following is the solution:-
Never use relative path in python scripts to be executed via crontab.
I did something like this instead:-
import os
import sys
import time, datetime
CLASS_PATH = '/srv/www/live/mainapp/classes'
SETTINGS_PATH = '/srv/www/live/foodtrade'
sys.path.insert(0, CLASS_PATH)
sys.path.insert(1,SETTINGS_PATH)
import other_py_files
Never supress the crontab code instead use mailserver and check the mail for the user. That gives clearer insights of what is going.
|
I have set up a cronjob for root user in ubuntu environment as follows by typing crontab -e
34 11 * * * sh /srv/www/live/CronJobs/daily.sh
0 08 * * 2 sh /srv/www/live/CronJobs/weekly.sh
0 08 1 * * sh /srv/www/live/CronJobs/monthly.sh
But the cronjob does not run. I have tried checking if the cronjob is running using pgrep cron and that gives process id 3033. The shell script calls a python file and is used to send an email. Running the python file is ok. There's no error in it but the cron doesn't run. The daily.sh file has the following code in it.
python /srv/www/live/CronJobs/daily.py
python /srv/www/live/CronJobs/notification_email.py
python /srv/www/live/CronJobs/log_kpi.py
|
CronJob not running
|
Running
nohup php artisan queue:work --daemon &
Will prevent the command exiting when you log out.
The trailing ampersand (&) causes process start in the background, so you can continue to use the shell and do not have to wait until the script is finished.
See nohup
nohup - run a command immune to hangups, with output to a non-tty
This will output information to a file entitled nohup.out in the directory where you run the command. If you have no interest in the output, you can redirect stdout and stderr to /dev/null; similarly, you could output it into your normal Laravel log. For example
nohup php artisan queue:work --daemon > /dev/null 2>&1 &
nohup php artisan queue:work --daemon >> storage/logs/laravel.log &
But you should also use something like Supervisord to ensure that the service remains running and is restarted after crashes/failures.
Use >> to append to laravel.log. Using a single > will replace the file each time.
|
I recently setup a Laravel Queue system. The basics are a cronjob calls a command which adds jobs to a queue and calls a second command which sends an email.
The system works when I ssh into my server and run php artisan queue:listen, but if I close my terminal the listener shuts down and the jobs stack up and sit in queue until I ssh back in and run listen again.
What is the best way to keep my queue system running in the background without needing to keep my connection open via ssh?
I tried running php artisan queue:work --daemon, and it completed the jobs in the queue, but when I closed my terminal it closed the connection and the background process.
|
How to keep Laravel Queue system running on server
|
In crontab system :
/usr/bin/php is php binary path (different in some systems ex: freebsd /usr/local/bin/php, linux: /usr/bin/php)
/home/username/public_html/cron/cron.php should be your php script path
/dev/null should be cron output , ex: /home/username/stdoutx.txt
So you can monitor your cron by viewing cron output /home/username/stdoutx.txt
|
I am just trying to run a PHP script using a cron job within CPanel - is this the correct syntax:
/usr/bin/php -q /home/username/public_html/cron/cron.php >/dev/null
I am not getting any email notifications stating a cron has been completed, do I need to do anything specific with the PHP file?
|
Run a PHP file in a cron job using CPanel
|
190
Here's my example crontab I always use as a template:
# Use the hash sign to prefix a comment
# +---------------- minute (0 - 59)
# | +------------- hour (0 - 23)
# | | +---------- day of month (1 - 31)
# | | | +------- month (1 - 12)
# | | | | +---- day of week (0 - 7) (Sunday=0 or 7)
# | | | | |
# * * * * * command to be executed
#--------------------------------------------------------------------------
To run my cron job every Monday, Wednesday and Friday at 7:00PM, the result will be:
0 19 * * 1,3,5 nohup /home/lathonez/script.sh > /tmp/script.log 2>&1
source
Share
Improve this answer
Follow
edited Sep 6, 2022 at 21:30
Benoit Duffez
12.1k1212 gold badges7777 silver badges126126 bronze badges
answered Jul 7, 2015 at 6:02
lathonezlathonez
2,37311 gold badge99 silver badges1212 bronze badges
3
You should avoid linking to external resources, as they might go away and make your answer useless.
– Thomas Fenzl
Jul 7, 2015 at 6:09
5
This is more a paste from documentation than an actual answer. You may edit your post to show the actual answer (0 19 * * 1,3,5)
– nicolallias
Dec 2, 2016 at 14:57
How about spring cron job expression which has 6 characters instead of 5?
– Shiva kumar
May 13, 2021 at 6:24
Add a comment
|
|
How can one run a cron job for every Monday, Wednesday and Friday at 7:00 pm?
|
How to run a cron job on every Monday, Wednesday and Friday?
|
You need to also install cygrunsrv so you can set cron up as a windows service, then run cron-config.
If you want the cron jobs to send email of any output you'll also need to install either exim or ssmtp (before running cron-config.)
See /usr/share/doc/Cygwin/cron-*.README for more details.
Regarding programs without a .exe extension, they are probably shell scripts of some type. If you look at the first line of the file you could see what program you need to use to run them (e.g., "#!/bin/sh"), so you could perhaps execute them from the windows scheduler by calling the shell program (e.g., "C:\cygwin\bin\sh.exe -l /my/cygwin/path/to/prog".)
|
Some cygwin commands are .exe files, so you can run them with the standard Windows Scheduler, but others don't have an .exe extension so can't be run from DOS (it seems like).
For example I want updatedb to run nightly.
How do I make cron work?
|
How do you run a crontab in Cygwin on Windows?
|
According to the man page of wget, there are a couple of options related to timeouts -- and there is a default read timeout of 900s -- so I say that, yes, it could timeout.
Here are the options in question :
-T seconds
--timeout=seconds
Set the network timeout to seconds
seconds. This is equivalent to
specifying --dns-timeout,
--connect-timeout, and
--read-timeout, all at the same
time.
And for those three options :
--dns-timeout=seconds
Set the DNS lookup timeout to seconds
seconds. DNS lookups that don't
complete within the specified time
will fail. By default, there is no
timeout on DNS lookups, other than
that implemented by system libraries.
--connect-timeout=seconds
Set the connect timeout to seconds
seconds. TCP connections that take
longer to establish will be aborted.
By default, there is no connect
timeout, other than that implemented
by system libraries.
--read-timeout=seconds
Set the read (and write) timeout to
seconds seconds. The "time" of
this timeout refers to idle time: if,
at any point in the download, no data
is received for more than the
specified number of seconds, reading
fails and the download is restarted.
This option does not directly
affect the duration of the entire
download.
I suppose using something like
wget -O - -q -t 1 --timeout=600 http://www.example.com/cron/run
should make sure there is no timeout before longer than the duration of your script.
(Yeah, that's probably the most brutal solution possible ^^ )
|
I'm running a PHP script via cron using Wget, with the following command:
wget -O - -q -t 1 http://www.example.com/cron/run
The script will take a maximum of 5-6 minutes to do its processing. Will WGet wait for it and give it all the time it needs, or will it time out?
|
Does WGET timeout?
|
Maybe this can help: Advanced Python Scheduler
Here's a small piece of code from their documentation:
from apscheduler.schedulers.blocking import BlockingScheduler
def some_job():
print "Decorated job"
scheduler = BlockingScheduler()
scheduler.add_job(some_job, 'interval', hours=1)
scheduler.start()
|
Before I ask, Cron Jobs and Task Scheduler will be my last options, this script will be used across Windows and Linux and I'd prefer to have a coded out method of doing this than leaving this to the end user to complete.
Is there a library for Python that I can use to schedule tasks? I will need to run a function once every hour, however, over time if I run a script once every hour and use .sleep, "once every hour" will run at a different part of the hour from the previous day due to the delay inherent to executing/running the script and/or function.
What is the best way to schedule a function to run at a specific time of day (more than once) without using a Cron Job or scheduling it with Task Scheduler?
Or if this is not possible, I would like your input as well.
AP Scheduler fit my needs exactly.
Version < 3.0
import datetime
import time
from apscheduler.scheduler import Scheduler
# Start the scheduler
sched = Scheduler()
sched.daemonic = False
sched.start()
def job_function():
print("Hello World")
print(datetime.datetime.now())
time.sleep(20)
# Schedules job_function to be run once each minute
sched.add_cron_job(job_function, minute='0-59')
out:
>Hello World
>2014-03-28 09:44:00.016.492
>Hello World
>2014-03-28 09:45:00.0.14110
Version > 3.0
(From Animesh Pandey's answer below)
from apscheduler.schedulers.blocking import BlockingScheduler
sched = BlockingScheduler()
@sched.scheduled_job('interval', seconds=10)
def timed_job():
print('This job is run every 10 seconds.')
@sched.scheduled_job('cron', day_of_week='mon-fri', hour=10)
def scheduled_job():
print('This job is run every weekday at 10am.')
sched.configure(options_from_ini_file)
sched.start()
|
Scheduling Python Script to run every hour accurately
|
0 * * * * cd folder_containing_exe && ./exe_name
should work unless there is something else that needs to be setup for the program to run.
|
I need to set up a cron job that runs an executable compiled using gcc once every hour.
I logged in as root and typed crontab -e
Then I entered the following and saved the file.
0 * * * * /path_to_executable
However, the cron job does not work.
I see that when I type /...path_to_executable I get a segmentation fault.
I can only execute the executable from the folder it is located in.
Is there a way I can solve this problem?
|
How to set up a cron job to run an executable every hour?
|
What about -mmin?
find /var/www/html/audio -daystart -maxdepth 1 -mmin +59 -type f -name "*.mp3" \
-exec rm -f {} \;
From man find:
-mmin n
File's data was last modified n minutes ago.
Also, make sure to test this first!
... -exec echo rm -f '{}' \;
^^^^ Add the 'echo' so you just see the commands that are going to get
run instead of actual trying them first.
|
This question already has answers here:
How to delete files older than X hours
(9 answers)
Closed 7 years ago.
I have this command that I run every 24 hours currently.
find /var/www/html/audio -daystart -maxdepth 1 -mtime +1 -type f -name "*.mp3" -exec rm -f {} \;
I would like to run it every 1 hour and delete files that are older than 1 hour. Is this correct:
find /var/www/html/audio -daystart -maxdepth 1 -mtime **+0.04** -type f -name "*.mp3" -exec rm -f {} \;
I am not sure of my use of the decimal number??
Thanks for any corrections.
EDIT
OR could I just use -mmin 60? Is this correct?
EDIT2
I tried your test, good thing you suggested it. I got an empty result. I want all files OLDER than 60mins to be deleted! How can I do this?? Does my command actually do this?
|
find -mtime files older than 1 hour [duplicate]
|
<property name="cronExpression" value="0 0/30 * * * ?" />
|
I have following Spring job to run after every 30 minutes. Please check my cron expression, is that correct?
0 0 0 * * 30
Here is a full cron job definition from the related Spring configuration file:
<bean id="autoWeblogPingTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobDetailForWeblogPing"/>
<!-- run every 35 minutes -->
<property name="cronExpression" value="0 0 0 * * 30" />
</bean>
|
Spring cron expression for every after 30 minutes
|
With one cron line, no. With three, yes:
# Every 15 minutes except for 3:00-3:59
*/15 0-2,4-23 * * * thejob
# 3:15, 3:30, 3:45
15-45/15 3 * * * thejob
# 3:00 dead
0 3 * * * otherjob
|
Is it possible to have a cronjob run every 15 minutes (over every hour etc..) except for at 3AM?
I have another special cronjob I want to run at 3AM, but I don't want the other one to run at the same time...
|
Crontab run every 15 minutes except at 3AM?
|
Cron utility is an effective way to schedule a routine background job at a specific time and/or day on an on-going basis.
Linux Crontab Format
MIN HOUR DOM MON DOW CMD
Example::Scheduling a Job For a Specific Time
The basic usage of cron is to execute a job in a specific time as shown below. This will execute the Full backup shell script (full-backup) on 10th June 08:30 AM.
Please note that the time field uses 24 hours format. So, for 8 AM use
8, and for 8 PM use 20.
30 08 10 06 * /home/yourname/full-backup
30 – 30th Minute
08 – 08 AM
10 – 10th Day
06 – 6th Month (June)
*– Every day of the week
In your case, for 2.30PM,
30 14 * * * YOURCMD
30 – 30th Minute
14 – 2PM
*– Every day
*– Every month
*– Every day of the week
To know more about cron, visit this website.
|
Right now i am running my cron job everyday at 3.00PM
0 15 * * *
But I want to run my cron job twice in a day. 10.30AM and 2.30PM
0 30 10 * * *
I believe this command will run at 10.30AM. How should i run it in 2.30PM?
|
Run CRON job everyday at specific time
|
Syntax 1
*/5+2 * * * * 1st-script
*/5+4 * * * * 2nd-script
For future reference take a look at this online Cron Job Generator.
Syntax 2
Since there are several reports that the + syntax is not working on Ubuntu 14.04, here's a variation:
2-59/5 * * * * 1st-script
4-59/5 * * * * 2nd-script
This will result in the 1st script to run every 5 minutes starting with an offset of 2 minutes at the beginning of each hour and the 2nd script to behave the same with an offset of 4 minutes.
|
I would like to have a script run every 5 minutes let's say starting from 13:02 so I can have another script runs every 5 minutes but starting from 13:04 so the second script runs two minutes after the start of the first job. How can I achieve this?
|
How can I run a cron job every 5 minutes starting from a time other than 0 minutes?
|
Could you try : cron(5,15,25,35,45,55 * * * ? *)
Cron expressions have six required fields here.
AWS documentation
EDIT: Also, don't miss this important wildcard note...
You cannot use * in both the Day-of-month and Day-of-week fields. If you use it in one, you must use ? in the other.
|
I'm trying to setup a Cloudwatch Scheduled Event and my cron expression seems to be invalid, though I can't figure out why.
My cron expression is:
cron(5,15,25,35,45,55 * * * *)
I want it to run on the 5th, 15th, 25th, 35th, 45th and 55th minute of every hour of every day. This seems to coincide with the AWS Scheduled Events documentation here http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html.
The above documentation allows for minutes to be represented with comma separated values between 0 and 59, and hours, day-of-month (or day-of-week), month and year to be reflected with a * wildcard to reflect ALL.
I have tried setting the cron expression on the Lambda console (when creating the function and choosing Cloudwatch Schedule Event), and in the Cloudwatch console (along with choosing the target of the trigger). Neither worked with my custom cron expression.
I have tried the following:
5,15,25,35,45,55 * * * *
5,15,25,35,45,55 * ? * *
cron(5,15,25,35,45,55 * * * *)
cron(5,15,25,35,45,55 * ? * *)
Everytime I get an error saying the ScheduleExpression is not valid. I can, however, use one of the premade rate() expressions.
How can I use my own custom cron expression?
Thanks.
|
Parameter ScheduleExpression is not valid
|
Same as you did for hours:
*/2 09-18 * * 1-5 /path_to_script
0 and 7 stand for Sunday
6 stands for Saturday
so, 1-5 means from Monday to Friday
|
I am trying to setup a cron job on a Ubuntu server. We want the cron job to run the script at certain times of the day and on some specific days of the week. For example, we want to setup a cron job that runs the script with the following sequence:
Execute the script every 2 minutes from 9 am to 2 pm during the weekdays.
This is what I have been able to do so far:
*/2 09-14 * * * /path_to_script
What should I do for the weekdays?
|
setup cron tab to specific time of during weekdays
|
just provide the full path to node /usr/local/bin/node in your cron job like:
30 6 1 * * /usr/local/bin/node /home/steve/example/script.js
|
Quite simply, I have node script that I want to execute once a month.
30 6 1 * * node /home/steve/example/script.js
But this doesn't work, presumably because of path or the shell the command is being ran under. I've tried the following means of executing node via cron (tested with -v):
steve@atom:~$ node -v
v0.4.2
steve@atom:~$ sh node -v
sh: Can't open node
steve@atom:~$ bash node -v
/usr/local/bin/node: /usr/local/bin/node: cannot execute binary file
steve@atom:~$ /usr/local/bin/node -v
v0.4.2
steve@atom:~$ sh /usr/local/bin/node -v
/usr/local/bin/node: 1: Syntax error: "(" unexpected
steve@atom:~$ bash /usr/local/bin/node -v
/usr/local/bin/node: /usr/local/bin/node: cannot execute binary file
I've ran out of ideas to try, any advice?
|
How can you execute a Node.js script via a cron job?
|
Create the backup (export):
crontab -l > /some/shared/location/crontab.bak
Import it from the new user:
crontab /some/shared/location/crontab.bak
|
How can I export the contents of the crontab to a file?
I need it because I'm switching usernames and do not want to lose the data in the crontab.
|
Export crontab to a file
|
As David intimated, the problem here is that gpg doesn't trust the public key you're using to encrypt. You could sign the key as he explained.
An alternative--especially if the key might be changing occasionally--would be to tack on --trust-model always to your gpg command.
Here's the relevant bit from the man page:
--trust-model pgp|classic|direct|always|auto
Set what trust model GnuPG should follow. The models are:
pgp This is the Web of Trust combined with trust signatures as used in
PGP 5.x and later. This is the default trust model when creating a
new trust database.
classic
This is the standard Web of Trust as used in PGP 2.x and earlier.
direct Key validity is set directly by the user and not calculated via
the Web of Trust.
always Skip key validation and assume that used keys are always fully
trusted. You generally won't use this unless you are using some
external validation scheme. This option also suppresses the
"[uncertain]" tag printed with signature checks when there is no
evidence that the user ID is bound to the key.
auto Select the trust model depending on whatever the internal trust
database says. This is the default model if such a database
already exists.
|
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
I am running next command within a crontab to encrypt a file and I don't want a keyboard interaction
echo "PASSPHRASE" | gpg --passphrase-fd 0 -r USER --encrypt FILENAME.TXT
but I have this answer:
gpg: C042XXXX: There is no assurance this key belongs to the named user
pub 40XXX/C042XXXX 2012-01-11 Name LastName. (comment) <[email protected]>
Primary key fingerprint: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
Subkey fingerprint: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
It is NOT certain that the key belongs to the person named
in the user ID. If you *really* know what you are doing,
you may answer the next question with yes.
Use this key anyway? (y/N)
|
gpg encrypt file without keyboard interaction [closed]
|
Every job that's run by systemd-cron (and most other implementations?) is run in the background automatically, so no need for the &.
|
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
In a crontab file, should commands be specified with a trailing "&", or will the command run in the background anyway?
I have:
*/20 * * * * /home/me/monitor/check.sh /home/me/monitor/check.properties >> /home/me/monitor/check.log 2>&1 &
I've seen contradictory answers to this question in various places. Some say no need to put an "&", others that without the ampersand cron waits for output from the command, even though all output is redirected.
|
Should linux cron jobs be specified with an "&" to indicate to run in background? [closed]
|
Based on the comments try
*/5 * * * * wget http://example.com/check
[Edit: 10 Apr 2017]
This answer still seems to be getting a few hits so I thought I'd add a link to a new page I stumbled across which may help create cron commands: https://crontab.guru
|
I'm newbie in cron commands and I need help.
I have a script on http://example.com/check/.
Whats is command for cron to run this URL every 5 minutes?
I tried
*/5 * * * * /home/test/check.php
But I want to run URL not relative script address. How to do it?
|
CRON command to run URL address every 5 minutes
|
148
You can enable logging for cron jobs in order to track problems. You need to edit the /etc/rsyslog.conf or /etc/rsyslog.d/50-default.conf (on Ubuntu) file and make sure you have the following line uncommented or add it if it is missing:
cron.* /var/log/cron.log
Then restart rsyslog and cron:
sudo service rsyslog restart
sudo service cron restart
Cron jobs will log to /var/log/cron.log.
Share
Improve this answer
Follow
edited Sep 18, 2020 at 9:41
jpihl
8,02133 gold badges3737 silver badges5151 bronze badges
answered Jan 19, 2016 at 8:41
Mehdi YedesMehdi Yedes
2,31522 gold badges1515 silver badges1414 bronze badges
1
4
After I did this, I could find this log. (CRON) info (No MTA installed, discarding output). so I installed postfix then I could see some logs by less /var/mail/<user>
– Kennyhyun
Sep 11, 2021 at 13:16
Add a comment
|
|
I have added a crontab entry on a Linux server that will run a Java executable. The Java code uses its own class for logging errors and messages into a log file.
But when I checked the log file after the scheduled time, no messages were logged. There should have been at least one log message saying the execution had started.
So there are two possible causes:
The code executed but didn't log;
Or, the code didn't execute at all.
The log file specified has chmod 777 permissions so I'm guessing it's the second cause here.
Why wouldn't a crontab job execute at its scheduled time? And how do I debug this without any kind of logging happening?
I have read that if there is an error cron sends an email to the user. How do I find out which email address is associated with the user?
|
Debugging crontab jobs
|
How about this, it does keep it in the crontab even if it isn't exactly defined in the first five fields:
0 6 * * Tue expr `date +\%W` \% 2 > /dev/null || /scripts/fortnightly.sh
|
I would like to run a job through cron that will be executed every second Tuesday at given time of day. For every Tuesday is easy:
0 6 * * Tue
But how to make it on "every second Tuesday" (or if you prefer - every second week)?
I would not like to implement any logic in the script it self, but keep the definition only in cron.
|
How to instruct cron to execute a job every second week?
|
To elaborate on Sougata Bose's answer, I think the OP wants a command to be run every 10 seconds from a start time; not 10 seconds after the first minute and every subsequent minute.
cron only has a resolution of 1 minute (there are other tools I think that may have finer resolutions but they are not standard on unix).
Therefore, to resolve your issue you need 60 seconds / 10 seconds = 6 cron jobs, each with a sleep.
e.g. run crontab -e and add the following lines to your chosen editor:
* * * * * ( /usr/bin/wget http://api.us/application/ )
* * * * * ( sleep 10 ; /usr/bin/wget http://api.us/application/ )
* * * * * ( sleep 20 ; /usr/bin/wget http://api.us/application/ )
* * * * * ( sleep 30 ; /usr/bin/wget http://api.us/application/ )
* * * * * ( sleep 40 ; /usr/bin/wget http://api.us/application/ )
* * * * * ( sleep 50 ; /usr/bin/wget http://api.us/application/ )
|
I need to run a CRON job every 10 seconds from started time.
In Linux how to run a CRON job on every 10 seconds from the time its started?
I am trying to solve that as following: when I make a request (or start) at 04:28:34 it should start at 04:28:44 not at 4:28:40
This is what I have done
# m h dom mon dow command
*/10 * * * * /usr/bin/wget http://api.us/application/
What did I do wrong? Why does this not trigger wget every 10 seconds?
|
How to setup CRON job to run every 10 seconds in Linux?
|
152
According to the Quartz CronTrigger tutorial (Quartz is used by www.cronmaker.com, referenced above), the ? wildcard is only used in the day of month and day of week fields:
? ("no specific value") - useful when you need to specify something in one of the two fields in which the character is allowed, but not the other. For example, if I want my trigger to fire on a particular day of the month (say, the 10th), but don't care what day of the week that happens to be, I would put "10" in the day-of-month field, and "?" in the day-of-week field.
I guess * isn't appropriate here because * means execute on every day of the week, which contradicts the rule saying that it should only run on the 10th of the month.
Share
Improve this answer
Follow
edited May 14, 2019 at 8:56
khylo
4,45033 gold badges3030 silver badges2424 bronze badges
answered May 2, 2014 at 15:37
Dan KingDan King
3,51055 gold badges2424 silver badges2424 bronze badges
1
1
In Spring Boot quartz CronExpression.isValidExpression("0 * * * * *") return false, CronExpression.isValidExpression("0 * * * * *") return true, but In Spring Boot scheduling tasks both of @Scheduled(cron = "0 * * * * *") or @Scheduled(cron = "0 * * * * ?") work fine
– free斩
Jul 3, 2018 at 12:31
Add a comment
|
|
Source Wikipedia:
Question mark (?) is used instead of '*' for leaving either day-of-month or day-of-week blank.
The above statement is not making much sense to me.
So if I write some cron as 0 0 0 ? * * then does it mean first of every month or it means it will execute daily?
It is a bit confusing as Java crons start with seconds while other crons start with minute.
|
Significance of question mark in Java cron
|
I would use cron to run a script every minute, and make that script run your script four times with a 15-second sleep between runs.
(That assumes your script is quick to run - you could adjust the sleep times if not.)
That way, you get all the benefits of cron as well as your 15 second run period.
Edit: See also @bmb's comment below.
|
I've seen a few solutions, including watch and simply running a looping (and sleeping) script in the background, but nothing has been ideal.
I have a script that needs to run every 15 seconds, and since cron won't support seconds, I'm left to figuring out something else.
What's the most robust and efficient way to run a script every 15 seconds on unix? The script needs to also run after a reboot.
|
How to get a unix script to run every 15 seconds?
|
87
Example using the 'disable' parameter:
from tqdm import tqdm
import time
for i in tqdm(range(10), disable=True):
time.sleep(1)
Share
Improve this answer
Follow
answered Apr 8, 2020 at 20:13
cannincannin
2,91522 gold badges2727 silver badges3232 bronze badges
1
2
That is a really good answer, which works perfectly fine as of January 2021.
– Yannik Suhre
Jan 6, 2021 at 8:42
Add a comment
|
|
I'm using tqdm to display progress bars while some long-running Django management commands complete. It works great (so easy to use!), but...
When I run unit tests over my code, I want to stop the progress bars from outputting. And if I run those commands in the background using cron or some other means, I'd also want the progress bars not to be in the output.
I can't see an easy way to do these two things, but perhaps I've missed something?
|
Silence tqdm's output while running tests or running the code via cron
|
If you're using "workon" you're actually using "virtualenv wrapper" which is another layer of abstraction that sits on top of virtualenv. virtualenv alone can be activated by cd'ing to your virtualenv root directory and running:
source bin/activate
workon is a command provided by virtualenv wrapper, not virtualenv, and it does some additional stuff that is not necessarily required for plain virtualenv. All you really need to do is source the bin/activate file in your virtualenv root directory to "activate" a virtualenv.
You can setup your crontab to invoke a bash script which does this:
#! /bin/bash
cd my/virtual/env/root/dir
source bin/activate
# virtualenv is now active, which means your PATH has been modified.
# Don't try to run python from /usr/bin/python, just run "python" and
# let the PATH figure out which version to run (based on what your
# virtualenv has configured).
python myScript.py
|
I want to set up a crontab to run a Python script.
Say the script is something like:
#!/usr/bin/python
print "hello world"
Is there a way I could specify a virtualenv for that Python script to run in? In shell I'd just do:
~$ workon myenv
Is there something equivalent I could do in crontab to activate a virtualenv?
|
How to set virtualenv for a crontab?
|
Depending on your version of cron, you should be able to do (for hours, say):
1-23/2
Going by the EXTENSIONS section in the crontab(5) manpage:
Ranges can include "steps", so "1-9/2" is the same as "1,3,5,7,9".
For a more portable solution, I suspect you just have to use the simple list:
1,3,5,7,9,11,13,15,17,19,21,23
But it might be easier to wrap your command in a shell script that will immediately exit if it's not called in an odd minute.
|
In crontab, I can use an asterisk to mean every value, or "*/2" to mean every even value.
Is there a way to specify every odd value? (Would something like "1+*/2" work?)
|
Specifying "all odd values" in crontab?
|
you may use this:
# m h dom mon dow command
0 13,14,15 * * * /home/user/command
your /home/user/command will be run at 13:00, 14:00 and 15:00
|
I am not sure how to run a cron job at 3 specific hours every day. I want to run it at 1pm, 2 pm and 3pm.
Is it possible, using a single expression?
|
Running a cron job 3 times (1 pm, 2 pm and 3 pm for example)?
|
Update: please read the other answers and comments as they contain more info (e.g., hash functions) that I did not know when I first answered this question.
According to Jenkins' own help (the "?" button) for the schedule task, 5 fields are specified:
This field follows the syntax of cron (with minor differences). Specifically, each line consists of 5 fields separated by TAB or whitespace:
MINUTE HOUR DOM MONTH DOW
I just tried to get a job to launch at 4:42PM (my approximate local time) and it worked with the following, though it took about 30 extra seconds:
42 16 * * *
If you want multiple times, I think the following should work:
0 16,18,20,22 * * *
for 4, 6, 8, and 10 o'clock PM every day.
|
How do I schedule a Jenkins build such that it would be able to build only at specific hours every day?
For example to start at 4 PM
0 16 1-7 * *
I understand that as, "at 0 minutes, at 4 o'clock PM, from Monday to Sunday, every month", however it builds every minute :(
I would be grateful for any advice. Thanks!
|
How to schedule a build in Jenkins?
|
104
The manpage of logrotate.conf contains an important advice for the hourly option:
Log files are rotated every hour. Note that usually logrotate is configured to be run by cron daily. You have to change this configuration and run logrotate hourly to be able to really rotate logs hourly.
As pointed out by yellow1pl the solution is to copy the file /etc/cron.daily/logrotate into the /etc/cron.hourly/ directory. This works at least for Debian and possibly some Debian derivates.
Share
Improve this answer
Follow
edited Aug 25, 2014 at 12:54
answered Aug 25, 2014 at 11:53
scaiscai
20.8k44 gold badges5656 silver badges7575 bronze badges
6
3
This also works in CentOS
– EminezArtus
Jun 12, 2015 at 15:18
10
Copy or move the file? Also, shouldn't I change "daily" to "hourly" inside /etc/logrotate.conf?
– Mario Mey
Jul 31, 2017 at 13:04
4
I would symlink as if the script gets updated you will inherit any changes. Also if you are using the dateext option you will need to reformat the extension so you can have multiple uniq filenames per day. I use the following. dateext dateformat -%Y%m%d-%s
– krad
Nov 28, 2017 at 15:00
5
The command I used for symlink: ln -s /etc/cron.daily/logrotate /etc/cron.hourly/logrotate
– Roland Pihlakas
Aug 12, 2020 at 17:53
This works with RedHat but at least with RH8 you need to execute sudo semanage permissive -a logrotate_t or otherwise /etc/cron.hourly/logrotate won't have permissions to edit the log files, no matter the daily version did. I didn't try a symbolic link instead. I don't know if there is a difference for SELinux.
– aalku
Oct 24, 2022 at 10:42
|
Show 1 more comment
|
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I tried to set up a log rotation of logs files located at /tmp/hr_logs/. For setting up, I used logrotate in linux and I'm able to rotate it on daily basis using the following config in my /etc/logrotate.conf
/tmp/hr_logs {
daily
rotate 4
With this config, file will rotate on daily basis and system will keep 4 copies of the log file appended with date [format: -YYYYMMDD]
Now, I trying to set up a different set of log files which I need to make rotate on hourly basis and for it, i have done the configuration in logrotate.conf:
/tmp/last_logs {
hourly
rotate 4
But this is not at all working? Can anyone please guide me on this please?
|
Hourly rotation of files using logrotate? [closed]
|
You'll notice that this doesn't exactly work in your shell, either.
What you need to do is put single quotes around the URL, like so:
curl -sS 'http://example.com/cronjob.php?days=1&month=1'
|
I'm running two cron jobs:
This one executes without a problem:
curl -sS http://example.com/cronjob.php?days=1
But this doesn't run at all:
curl -sS http://example.com/cronjob.php?days=1&month=1
Is this because of the ampersand (&)? If yes, how to pass multiple parameters?
Using argv is not an option.
|
How to pass multiple parameters to cron job with curl?
|
Just follow these steps:
In Terminal: crontab -e.
Press i to go into vim's insert mode.
Type your cron job, for example:
30 * * * * /usr/bin/curl --silent --compressed http://example.com/crawlink.php
Press Esc to exit vim's insert mode.
Type ZZ to exit vim (must be capital letters).
You should see the following message: crontab: installing new crontab. You can verify the crontab file by using crontab -l.
Note however that this might not work depending on the content of your ~/.vimrc file.
|
I would like to use cron on my Mac. I choose it over launchd, because I want to be able to use my new knowledge on Linux as well. However, I cannot seem to get the crontab -e command to work. It fires up vim, I enter my test job:
0-59 * * * * mollerhoj3 echo "Hello World"
But after saving and quitting (:wq),
crontab -l
says:
No crontab for mollerhoj3
What am I doing wrong?
|
Why I've got no crontab entry on OS X when using vim?
|
You can put something like this in the crontab file:
00 09 * * 7 [ $(date +\%d) -le 07 ] && /run/your/script
The date +%d gives you the number of the current day, and then you can check if the day is less than or equal to 7. If it is, run your command.
If you run this script only on Sundays, it should mean that it runs only on the first Sunday of the month.
Remember that in the crontab file, the formatting options for the date command should be escaped.
|
I am using Bash on RedHat. I need to schedule a cron job to run at at 9:00 AM on first Sunday of every month. How can I do this?
|
How to schedule to run first Sunday of every month
|
Try this out to execute a command on 30th March 2011 at midnight:
0 0 30 3 ? 2011 /command
WARNING: As noted in comments, the year column is not supported in standard/default implementations of cron. Please refer to TomOnTime answer below, for a proper way to run a script at a specific time in the future in standard implementations of cron.
|
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
How do I set up cron to run a file just once at a specific time? One of the alternatives is at but it is not accessible to all users on standard hosting plans. Therefore I was wondering whether there is way to do it using cron?
|
How do I set up cron to run a file just once at a specific time? [closed]
|
As seen in Install crontab on CentOS, the crontab package in CentOS is vixie-cron. Hence, do install it with:
yum install vixie-cron
And then start it with:
service crond start
To make it persistent, so that it starts on boot, use:
chkconfig crond on
On CentOS 7 you need to use cronie:
yum install cronie
On CentOS 6 you can install vixie-cron, but the real package is cronie:
yum install vixie-cron
and
yum install cronie
In both cases you get the same output:
yum install vixie-cron
0
|
I am familiar to setup the cron scheduler using crontab -e command on my centos. But today I found one of my centos servers doesn't have this command
I have tried to install this using yum install crontab but no luck. Then I tried yum install crontabs and it installed something
=============================================================================
Package Arch Version Repository Size
=============================================================================
Updating:
crontabs noarch 1.10-11.el5 base 7.0 k
Transaction Summary
=============================================================================
Install 0 Package(s)
Update 1 Package(s)
Remove 0 Package(s)
Total download size: 7.0 k
Is this ok [y/N]:
But still the crontab command doesn't work. If I do cat /etc/crontab then it shows below thing
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
40 * * * * root run-parts /etc/cron.hourly
54 1 * * * root run-parts /etc/cron.daily
14 3 * * 0 root run-parts /etc/cron.weekly
38 1 16 * * root run-parts /etc/cron.monthly
What should I do to have crontab on that particular server? I am using centos0.
grep on cron shows:
centos1
starting cron service returns:
centos2
|
How to install crontab on Centos
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.