Easy About Bash Script function


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Easy About Bash Script function
# 1  
Old 04-01-2009
Bug Easy About Bash Script function

Hi to all,

first of all,i am working on MINIX 3 OS.
I want to create a bash script file,which will create a list of files(not directories) that have been modified one specific day (i.e today) under my home directory.

thank you very much!! Smilie
# 2  
Old 04-01-2009
Look at the man pages for "find" command. Roughly what you're looking for:

#!/bin/bash
find $HOME -daystart -ctime 0 -type f >files_today.list # files modified today
find $HOME -daystart -ctime 1 -type f >files_yesterday.list # files modified yesterday

I'm not sure that "daystart" may be a Linux extension. If your OS doesn't support it, you can still accomplish this with ctime piped into a grep. My OS has date field in format "Mon dd" where dd is two-digit day with no leading zero. So April 1st would be:
"Apr 1" (i.e., two spaces between r and 1). So I would do:

#!/bin/bash
find $HOME -ctime 0 -type f | grep "Apr 1" >files_today.list
find $HOME -ctime 0 -type f | grep "Mar 31" >files_yesterday.list
find $HOME -ctime 1 -type f | grep "Mar 31" >>files_yesterday.list
# 3  
Old 04-01-2009
hi marcus!

with this line:

find $HOME -daystart -ctime 0 -type f >files_today.list # files modified today

you take the list with the files modified today or also the files that are created today?which is the parameter that ensure this?Smilie
# 4  
Old 04-01-2009
Broken down
Code:
$ find \      # Command
  $HOME \     # Directory
  -daystart \ # Use the start of the day as base for time calculations
  -ctime 0 \  # ctime (Change time, either content or metadata) in the last
              # 24 hours
  -type f \   # Only regular files

# 5  
Old 04-01-2009
Quote:
Originally Posted by pludi
Broken down
Code:
$ find \      # Command
  $HOME \     # Directory
  -daystart \ # Use the start of the day as base for time calculations
  -ctime 0 \  # ctime (Change time, either content or metadata) in the last
              # 24 hours
  -type f \   # Only regular files

maybe i didn't express me so good.My question is which files are been found with this.Not since when. i.e. Just modified files or also created files?
# 6  
Old 04-01-2009
Both. Change time is always the time of the last content or metadata change. Metadata changes include file creation, renaming, moving, permissions, ...
# 7  
Old 04-01-2009
Ahhh..Ok thanks for the note..I understand now how it works.. :-)


According to this,If you want to take all the backup files that have been modified today (as marcus described good before) with the command "tar", and put them in a file *.tar, putting also the date as a name of the file...for example like Backup_of_01_04_2009.tar.. any ideas how to implement this.??? :-)

Thanks a lot!!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script: problem with a function which use colors

Hello guys :) I've a some issue with a function which use the bash colors in my script. An example : #!/bin/bash set -x log_in(){ host="srv1" remote_files="log/" LOG_FILE="logfile" green='\033]; then color_in_red=("${red}"$2"${none}") echo -e... (2 Replies)
Discussion started by: Arnaudh78
2 Replies

2. Shell Programming and Scripting

Bash script fails with "function: not found" error

Hello everyone, I am having problems figuring this out. This script below is supposed to create a list of file names with their "md5sum", in a file "lib-list.txt" When I run it "sh component-list.sh " I get this:component-list.sh: 4: component-list.sh: function: not found component-list.sh:... (4 Replies)
Discussion started by: joemb
4 Replies

3. Shell Programming and Scripting

Calling function from another bash script

I would like to call functions from another bash script. How can I do it? Some code More code (11 Replies)
Discussion started by: kristinu
11 Replies

4. Shell Programming and Scripting

Passing parameters to bash script function (or subroutine)

I've found a few posts regarding passing parameters to a function or subroutine, but for some reason when I try to run a command based on part with these parameters it's not working. If I have the function echo the parameters they show correctly so I believe they are being passed right but the... (2 Replies)
Discussion started by: withanh
2 Replies

5. Shell Programming and Scripting

Help with grep and read function in a BASH Script

I'm putting together a script that will search my mail archives for emails that meet certain criteria and output the files to a text file. I can manually cat that text file and pipe it into sendmail and it will work (i.e. cat /pathtofile/foo.txt | sendmail -t me@company.com) My script sends... (7 Replies)
Discussion started by: binary-ninja
7 Replies

6. Shell Programming and Scripting

bash script function parameters

I have a question about bash script. Can I create a function there that accept parameters like functions in program language? (2 Replies)
Discussion started by: programAngel
2 Replies

7. Shell Programming and Scripting

error when call function in bash script

Dear all, Could you please advice as I when call function i found the following error " refills: command not found" note that refills is function name. following also the function and how i call it function refills { echo "formatting refills and telepin" >> $log awk -F,... (20 Replies)
Discussion started by: ahmed.gad
20 Replies

8. Shell Programming and Scripting

Run function from script over ssh (BASH)

Hi, Is there any cleaver way to run function from the bash scrip over ssh? For example: #!/bin/bash #Function 1 FN1 () { ls -l } #Main run ssh user@host FN1 exit 0 Yeah, I know it will not work, but I'm asking how to make it to work :) I'm suspecting that it would be... (1 Reply)
Discussion started by: columb
1 Replies

9. UNIX for Dummies Questions & Answers

Alias, function or script (bash) to "revert" cd command?

In all of my brief and superficial experience with Unix or Linux, the one curious and consistent thing has been that 'cd ./' (back up one directory level) has done absolutely nothing in any of them. Now I understand that, at least for bash, 'cd ./' appears to have been substituted by 'cd ..' Am... (1 Reply)
Discussion started by: SilversleevesX
1 Replies

10. Shell Programming and Scripting

Running function or command concurrently in a bash script

I currently run a script over a vpnc tunnel to back-up my data to a remote server. However for a number of reasons the tunnel often collapses. If I manually restore the tunnel then the whole thing can continue, but I want to add into my script a section whereby while the transfer is taking place,... (8 Replies)
Discussion started by: dj_bridges
8 Replies
Login or Register to Ask a Question