My requirement is to search for current date-1 .log files in /usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs folder and write the file name to filenames.txt
When I ran the script below, I got error as
syntax error near unexpected token `do
I'm not sure what is wrong in my code. I seek some help to achieve this task effeftively
#!/bin/sh
for i in /usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/"SASApp_STPServer_"$(date +%Y-%m-%d --date "1 day ago")"_tmptcmsaslva2_"*".log"
do
echo $i
done
echo $i >> output_file.txt
Could you please try following and let me know if this helps.
#!/bin/sh
for i in "/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_"$(date +%Y-%m-%d --date "1 day ago")"_tmptcmsaslva2_"*".log"
do
echo $i
done
If you are happy with above command's result then please change echo $i to echo $i >> output_file.txt
I repeat: "What operating system are you using?" And, since you're using ssh , show us the exact ssh command you're executing and tell us what operating system you're using on the system where you're running ssh and what operating system you're using on the system you're connecting to with ssh .
I use SSH secure client which is a windows application and then select the server which I need to connect by supplying username and password.
Then I will navigate to 'New terminal window' from the tool bar in SSH secure client and then I will go to the directories to develop\run a shell script.
If you need any further information about my environment, kindly advise me the steps which you want me to look for.
Thanks.
---------- Post updated at 02:27 AM ---------- Previous update was at 01:43 AM ----------
-bash-4.1$ uname -a
Linux serername x86_64 x86_64 GNU/Linux
-bash-4.1$ type bash date sh
bash is /bin/bash
date is /bin/date
sh is /bin/sh
-bash-4.1$ ls -l /bin/bash /bin/date /bin/sh
-rwxr-xr-x 1 root root 938832 Jul 9 2014 /bin/bash
-rwxr-xr-x 1 root root 59392 Oct 17 2014 /bin/date
lrwxrwxrwx 1 root root 4 Mar 4 2015 /bin/sh -> bash
-bash-4.1$
-bash-4.1$ date +%Y-%m-%d --date "1 day ago"
2015-08-27
-bash-4.1$
[/CODE]
---------- Post updated at 04:34 AM ---------- Previous update was at 03:45 AM ----------
I managed to get output now. THere was a line feed issue earlier.
My output file (output_file.txt) Contains filenames alongwitH direCtories like below.
Why are so many letters within a word in caps? (your first posts were good)
Please try to write proper grammer -> Nobody is perfect and many here are not native english speakers/writers/readers -> and i know of no language having capital letter within a word.
If that happens by accident, please clean your keyboard.
cd /usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs
for i in "SASApp_STPServer_$(date +%Y-%m-%d --date "1 day ago")_tmptcmsaslva2_"*.log
do echo "$i"
done > output_file.txt
or, assuming that your list of files won't exceed ARG_MAX limits, just:
cd /usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs
printf '%s\n' "SASApp_STPServer_$(date +%Y-%m-%d --date "1 day ago")_tmptcmsaslva2_"*.log > output_file.txt