Ubuntu :: Use The Date Command In A Simple Bash Script?
Oct 26, 2010
I am trying to use the date command in a simple bash script as below:
#!/bin/sh
this_date=`date`
echo "The date is $this_date"
This script seems to work only if a surround the command with the `` characters, which I copied from another script. Can anyone tell me why this is, and how I can insert these characters from my keyboard,which only has normal quote and double-quote characters?
I would like to write a shell script that displays the number of days, hours and seconds left until a certain date and time. What commands would I use?
When I run this command from shell, it runs ok export REVS=`svn info svn+ssh://svn.myone.ca/var/svn/story/trunk/lib |grep 'Last Changed Rev:'| awk -F: '{print $2}'` However when I save it into a file called test.sh (of course, I chmod it with +x), I got error "export: 2: bad variable name"
Here is the file: #!/bin/bash export REVS=`svn info svn+ssh://svn.myone.ca/var/svn/story/trunk/lib |grep 'Last Changed Rev:'| awk -F: '{print $2}'` I am using ubuntu.
Ive been using linux for a while but I am just getting into shell scripting, im currently trying to get a simple script for finding and copying files powered by the command:
Code:
This works fine from the command line but when put in a script such as:
Code:
Code:
with the keyboard inputs for $fc1 and $fc2 being *.doc and ~/test respectivly. The only problem i can see is the xargs -ivar "var" part possibly needing $var to be defined?
and now I want to calculate the average of the resulting numbers. I know I could write a bash or awk or perl script and use that, but isn't there a more simple, elegant way? There is for example "sum" in the coreutils, but no "avg"..
I have been looking at: ut a lot of it is to do with files and numerical comparisonswhat would be the bash equivalent of:if (http isin $2) { do something }
I am trying to create a function that takes a pair of a high and a low limit, and returns an arbitrary number between them. Below is my attempt to create a function that accomplishes this by checking to see if they are equal, and if not, subtracts a very small number from the high limit and returns the result.
This might well be a case of "I've been looking at terminals for far too long", but here goes. In a bash script I'm writing I'd like to get the current minute of the day. Since date doesn't have an in-built format string for that, I thought I would do:minute of day = 60 * hour of day + minute of hourHowever, when the clock rolled around to 12 / 0 the value disappears from the variable. Viz:
Are there any tools that can be used to create a simple GUI for the bash script files i have created, and the GUI should be able to run on both Solaris and Red Hat systems.
I wrote this script which works but it should run automatically about once per week. I hunted and experimented with KDE Task Scheduler (no dice and no help anywhere) and cron (confusing instructions and cannot edit crontab -e with vim, and cannot enter cron folders/files). I would settle for a desktop shortcut to run the script but found no for that.
I am running a simple script that I copied from slug.ceca.utc.edu/docs/2009-3-26-linux-server-health.pdf and edited with the names and paths of my own servers. I don't know much about scripting (re: nothing) but I wanted to try and be efficient in my new role as a Linux Sys Admin. The script was saved to root's home directory and runs as part of root's crontab once a week. The script runs with no problem, but it doesn't actually seem to run all of the commands contained within. It skips some in the middle and the end and I don't know why. The script itself is this:
I have a folder of 2 many files that the old ls just hangs.
I am trying to write some log files such as;
I don't mind doing one at a time, but I am just playing and even getting the listing I am not getting the date stamp, I have the following;
That does create the file, but all the files look like this;
So basically it's just sticking that ls inside the log file and not actually running the ls, so how can I use the above type to get files just created per year?
I have used "FILENAME="`TZ=$TZ+24 date +%y%m%d`" in a bash script that run in openbsd. What my script does is to changes a file name to "yesterdays date". I tried to use it in a script that runs in debian but it doesnt work. Is there any other command that i can use in debian?
Is there any other short/easier and smarter way to do the following in Linux? code...
I need to use crontab to create folders every day and every month inside /home/abcd/dammi, /home/abcd/harrami, /home/wxyz/dammi and /home/wxyz/harrami. Can anyone help me with this?
I've recently inherited a bunch of files at a new job and am trying to figure out some of the problems that have constantly popped up. The one i'm getting a huge headache with results from a bash script that is supposed to change a date format from a client populated txt field to one we want defined a certain way. Everything in the script works fine, except that one function. Below is the line i'm trying to manipulate, with date examples.
The one caveat is that the first date is non-static and changes daily. It is, however, always the current date. If it helps, the second date will always be a year away from the first date.My idea was to pull the current date via perl's DATE function, but...how to do it, and calculate a year away without throwing the rest of the bash script off? Any help would be appreciated. I'm sure it's a simple solution but i know absolutely nothing about these scripts and how they were written.
I need show the number of process per user, and after the date of the oldest process per user also.
With "ps -eo user | sort -u" i get all users that are running any process. And with "ps U username | wc -l" i get the number of process that the user "username" is running.
But how can i merge both commands for do what i need? Like a FOR or something like that. There is any method of make a FOR using the list that i get with the first command?
And then for show the date of the oldest process.. with "ps U username | sort -k 4" (4 is TIME field) i can show the process of the user "username" sorting they by time. But how can i get the date of the process takes longer running?? I can get only the time, but no the date.
How would i make ubuntu just execute this Code: deluged -p 10002 -c ~/delugebig/ at startup? Just print it as if i myself would print it in the termial.
I need this script but I don't know how to do it I have one folder with several folders inside.On each folder a have one MKV or AVI file inside...What I need is a script to change the "modification date" of each folder to the "modification date" of each MKV or AVI that the folder has inside.
I wanted to know if there was a simple command for the default sound in ubuntu. An example would be typing volume = 42 into the terminal or something. I'm not looking for alsamixer or anything like that, but maybe thats the only option.
I create a bash script that writes another bash file. But in the generated bash file I want to write a bash command in the file and not executing it.Here's my bash file:
Code: #!/bin/bash cat > ~/generateGridmix2data.sh << END
I need a program that automaticly runs this command in the terminal when I use it: sudo modprobe nvidia_g210m_acpi Sure, I know that it's not that hard to just write it in terminal and so on, but I really want a program for it. I'm using ubuntu 11.04 if U need to know that?