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 7 years ago.
Improve this question
Here is my crontab entry:
* * * * * /home/ec2-user/Test/test_thing.sh
Here is the script, test_thing.sh:
echo "asdf" >> ./bla.txt
When I run it manually, it does generate the "bla.txt" file. However, it does not automatically do so (create the "bla.txt" file within the /Test/ directory) with the crontab.
I have also checked my /var/log/cron file and I see that it is executed every minute, but not sure if it's running into an error or not.
If it is important, I am running this on an Amazon ec2 server, specifically the Amazon Linux AMI.
Edits:
I have also done chmod +x test_thing.sh to make sure it is executable.
The cronjob runs from home directory by default. So you should see the file to be created under /home/ec2-user or /root if you run it by root account.
If you need generate the new file with the nominate path, one way is to use absolute path as #yftse said. The other way is
* * * * * cd /home/ec2-user/Test/; bash /home/ec2-user/Test/test_thing.sh
Related
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
Going through this tutorial, I had to execute the command export PATH=~/.local/bin:$PATH
It explained with
This command inserts the path, ~/.local/bin in this example, at the
front of the existing PATH variable.
However, I still don't understand what exactly is happening there. What is the goal/effect of that command?
This command prepend the folder ~/.local/bin (~ is your home folder) to your global variable $PATH (echo $PATH too see it).
Thanks to that, you'll be able to execute program/script stored in the folder ~/.local/bin without typing the full path.
Example, if you have a script myScript.sh in your folder, before adding ~/.local/bin to your $PATH, you can run it with the command:
~/.local/bin/myScript.sh
After adding ~/.local/bin to your $PATH, you can execute it with the command:
myScript.sh
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 started learning Bash on Mint Linux. The thing is I want to know how to open and execute programs. I have a test.sh in my junk directory so that I can mess around but when ever I type in gnome-open test.sh it just opens the file and not actually run it. In the test.sh file I have echo hi in there so that I can see that it worked and I gave the file the permissions for it to be an executable file so it should execute.
You need to do two things:
Give the file execution permission (+x)
Execute the file
First you give the file permission no 755:
chmod 755 test.sh
Then you start it:
./test.sh
The dotslash means "current directory", it's like saying c:\file.bat if \ is the current directory. You need that because the current dir (called PWD) is not in your PATH variable which means that you either need to specify the complete path, eg. /users/user/file.sh or using the dot which is a shortcut for the current directory.
The file permission number 755 means:
owner: 7 (read, write, exec)
group: 5 (read, exec)
other: 5 (read, exec)
If you want to be the only one to be able to even open the file you may specify 700 instead. There are plenty of combinations, but 755 is most commonly used for scripts.
edit:
I forgot to mention that you need the dotslash everytime you run the script, but you only need to issue the chmod command once for every file.
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 know each part of this command.
sudo mv home/* *
sudo: super-user do, execute with root privileges.
mv: move a file or directory.
home/*: argument of mv command. It indicates the content of home directory. The asterisk * is a wildcard that expands to the list of files in the current directory in lexicographic order.
The next argument is the destiny folder. However, I specify an asterisk as destiny directory, and if I execute the command the folder disappear completely. So, what does the * in this case?
Let's say you have /home/userA, /home/userB and /home/userC. Let's further say you're running this in a directory that contains 1.txt, 2.txt, and a directory 3.d.
Under those circumstances, this would expand to:
sudo mv /home/userA /home/userB /home/userC 1.txt 2.txt 3.d
That is to say, both globs are expanded -- the first to the list of entries in /home, an the subject to the list of files in the current working directory -- and the result is everything being moved into the directory 3.d.
Flagged Community Wiki since this is an answer to an off-topic question.
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 6 years ago.
Improve this question
I've been playing around with getting crontab to run a tar command on a scheduled basis however it appears to not actually run the task at the intervals at all.
The line of code I've put into my crontab file is as follows.
1 * * * * tar cvf backup.tar . >> ~/testcron.log
The tar command works by itself if I run it in terminal so I'm not sure why this doesn't run.
Thanks
There are two things here which I can imagine being problematic:
If this is part of a file in /etc/crontab.d or part of /etc/crontab, cron expects a user name in the 6th column. So it would be something along the lines of:
1 * * * * root tar cvf backup.tar . >> ~/testcron.log
You might want to replace . with a proper absolute path. I would not be sure what the current directory is when cron executes the cronjob, so just use an absolute path.
Unable to post as a comment
cron PATH variable may be different from your user PATH variable
If this is the case, you will either have to specify the absolute path to the tar executable or export your local PATH to the crontab
More information here
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
Ok, so I'm trying to set cron to run a bash script at a certain time. My bash script is essentially this
#!/bin/bash
espeak -g 3 "this is my text"
So from there, I went to the crontabs, and added in
*/1 * * * * /path/to/my/script.sh
to see if it would run, but it didn't do anything. I changed the script to
#!/bin/bash
echo "this is my script"
to see if that would do anything, but no avail. Any help? Thanks.
Try to run the script manually and see if it echos out: bash /path/to/my/script.sh
Does the file have the correct permissions?
Try Outputting errors to a log file: */1 * * * * /path/to/my/script.sh > /path/to/my/error.log 2>&1