devries Posted March 11, 2006 Report Share Posted March 11, 2006 I want to have an date output in this format: 2006-03-11 How do I do that? The link is: http://files.ad.nl/strips/image.php?strip=...atum=2006-03-11 I have: #! /bin/bashurl="http://files.ad.nl/strips/image.php?strip=dirkjan&datum=" printf "${url}$(date)" But that doesn't work. Quote Link to comment Share on other sites More sharing options...
ianw1974 Posted March 11, 2006 Report Share Posted March 11, 2006 I did this, but it only works on the positioning of the characters of the url you specified. This was for testing, so you could see it works: echo "http://files.ad.nl/strips/image.php?strip=dirkjan&datum=2006-03-11" | cut -c 57-67 and the results: [ian@esprit ~]$ cat test echo "http://files.ad.nl/strips/image.php?strip=dirkjan&datum=2006-03-11" | cut -c 57-67 [ian@esprit ~]$ ./test 2006-03-11 Obviously if the url length changes, you need to change the digits at the end which specify cutting characters from position 57 to 67. Or find a way of getting cut to calculate the position of the date based on a field character. See this example for pulling uid from /etc/passwd: [ian@esprit ~]$ cat /etc/passwd | grep ian | cut -f 3 -d : 500 you might be able to get the same to work. To get the gid instead of uid, you change the "3" to a "4" and so on for other info. Actually, I just used that too: [ian@esprit ~]$ cat test echo "http://files.ad.nl/strips/image.php?strip=dirkjan&datum=2006-03-11" | cut -f 3 -d = [ian@esprit ~]$ ./test 2006-03-11 and works, as there are two equals signs splitting it into 3 parts, so choosing the 3rd part, using delimeter =. If a third equals sign was listed, then the date would be in the fourth field part, and therefore having to change the "3" to a "4" to get it to work. Quote Link to comment Share on other sites More sharing options...
jboy Posted March 11, 2006 Report Share Posted March 11, 2006 I want to have an date output in this format: 2006-03-11 #! /bin/bashurl="http://files.ad.nl/strips/image.php?strip=dirkjan&datum=" printf "${url}$(date)" But that doesn't work. Try this: echo $url`date +%Y`-`date +%m`-`date +%d` or printf $url`date +%Y`-`date +%m`-`date +%d` Quote Link to comment Share on other sites More sharing options...
paul Posted March 12, 2006 Report Share Posted March 12, 2006 date +%Y-%m-%d result = 2006-03-12 Quote Link to comment Share on other sites More sharing options...
devries Posted March 12, 2006 Author Report Share Posted March 12, 2006 date +%Y-%m-%d I tried that first because it looked the easist and what do you know... it worked. :D the script now looks like: #! /bin/bashurl="http://files.ad.nl/strips/image.php?strip=dirkjan&datum=$(date +%Y-%m-%d)" imgname=/home/xxxxx/tmp/dirkjan.jpg wget -qO $imgname "$url" echo -n "$imgname" Because komics uses kuickshow to show the actual comic and it needs for the file to have an extension. It's working again now so I hope the newspaper will keep this adress. I hate it when they change things. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.