I am totally new to shell scripting, and I am trying to insert the current date to a column in a database table using bash.
Here is what I have done so far:
CREATE TABLE DiskUsage (id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, DiskUsage VARCHAR(50), DateOfUsage DATETIME);
The table DiskUsage is successfully created in shelltest database.
Now, I am trying to insert values in this table using shell script:
dateOfUse=$(TZ=EEST date)
echo "Date: $dateOfUse"
$(df -h > t.txt)
while read Filesystem Size Used Avail Use Mounted on
do
mysql shelltest -e "insert into DiskUsage (DiskUsage, DateOfUsage) values ('$Use', '$dateOfUse')"
done < t.txt
But when I try to execute this script, the date value for DateOfUsage is being inserted like this:
0000-00-00 00:00:00 for all the records.
Can someone please tell me where I am mistaking? Thanks :)
echo "Date: $dateOfUse"??NOW()actually is acurrent_timestamp. If you want to use specific date then you follow answer, by @FreudChicken, below.