Sponsored Content
Top Forums Shell Programming and Scripting How to add missing date and time in a bash script? Post 302964421 by ernesto on Thursday 14th of January 2016 09:24:42 AM
Old 01-14-2016
Hi RudiC,

None, i have commented the awk part on the script. Please see details below.

SCIPT
Code:
[dev:Desktop]$ cat test.sh 
#!/bin/sh
read FD <test1.txt
FS=$(date -d "${FD% *}" +%s)

seq -f"@%.0f" $FS -60 $((FS-7200)) | date -f- +"%F %H:%M 0"  > ernie.txt
#awk 'NR == FNR {T[$1,$2] = $3
#                 next
#               }
#l
#END            { for (t in T) print t, T[t]
#               }
#' SUBSEP=" "

OUTPUT
Code:
[dev:Desktop]$ cat ernie.txt
2016-01-13 01:33 0
2016-01-13 01:32 0
2016-01-13 01:31 0
2016-01-13 01:30 0
2016-01-13 01:29 0
2016-01-13 01:28 0
2016-01-13 01:27 0
2016-01-13 01:26 0
2016-01-13 01:25 0
2016-01-13 01:24 0
2016-01-13 01:23 0
2016-01-13 01:22 0
2016-01-13 01:21 0
2016-01-13 01:20 0
2016-01-13 01:19 0
2016-01-13 01:18 0
2016-01-13 01:17 0
2016-01-13 01:16 0
2016-01-13 01:15 0
2016-01-13 01:14 0
2016-01-13 01:13 0
2016-01-13 01:12 0
2016-01-13 01:11 0
2016-01-13 01:10 0
2016-01-13 01:09 0
2016-01-13 01:08 0
2016-01-13 01:07 0
2016-01-13 01:06 0
2016-01-13 01:05 0
2016-01-13 01:04 0
2016-01-13 01:03 0
2016-01-13 01:02 0
2016-01-13 01:01 0
2016-01-13 01:00 0
2016-01-13 00:59 0
2016-01-13 00:58 0
2016-01-13 00:57 0
2016-01-13 00:56 0
2016-01-13 00:55 0
2016-01-13 00:54 0
2016-01-13 00:53 0
2016-01-13 00:52 0
2016-01-13 00:51 0
2016-01-13 00:50 0
2016-01-13 00:49 0
2016-01-13 00:48 0
2016-01-13 00:47 0
2016-01-13 00:46 0
2016-01-13 00:45 0
2016-01-13 00:44 0
2016-01-13 00:43 0
2016-01-13 00:42 0
2016-01-13 00:41 0
2016-01-13 00:40 0
2016-01-13 00:39 0
2016-01-13 00:38 0
2016-01-13 00:37 0
2016-01-13 00:36 0
2016-01-13 00:35 0
2016-01-13 00:34 0
2016-01-13 00:33 0
2016-01-13 00:32 0
2016-01-13 00:31 0
2016-01-13 00:30 0
2016-01-13 00:29 0
2016-01-13 00:28 0
2016-01-13 00:27 0
2016-01-13 00:26 0
2016-01-13 00:25 0
2016-01-13 00:24 0
2016-01-13 00:23 0
2016-01-13 00:22 0
2016-01-13 00:21 0
2016-01-13 00:20 0
2016-01-13 00:19 0
2016-01-13 00:18 0
2016-01-13 00:17 0
2016-01-13 00:16 0
2016-01-13 00:15 0
2016-01-13 00:14 0
2016-01-13 00:13 0
2016-01-13 00:12 0
2016-01-13 00:11 0
2016-01-13 00:10 0
2016-01-13 00:09 0
2016-01-13 00:08 0
2016-01-13 00:07 0
2016-01-13 00:06 0
2016-01-13 00:05 0
2016-01-13 00:04 0
2016-01-13 00:03 0
2016-01-13 00:02 0
2016-01-13 00:01 0
2016-01-13 00:00 0
2016-01-12 23:59 0
2016-01-12 23:58 0
2016-01-12 23:57 0
2016-01-12 23:56 0
2016-01-12 23:55 0
2016-01-12 23:54 0
2016-01-12 23:53 0
2016-01-12 23:52 0
2016-01-12 23:51 0
2016-01-12 23:50 0
2016-01-12 23:49 0
2016-01-12 23:48 0
2016-01-12 23:47 0
2016-01-12 23:46 0
2016-01-12 23:45 0
2016-01-12 23:44 0
2016-01-12 23:43 0
2016-01-12 23:42 0
2016-01-12 23:41 0
2016-01-12 23:40 0
2016-01-12 23:39 0
2016-01-12 23:38 0
2016-01-12 23:37 0
2016-01-12 23:36 0
2016-01-12 23:35 0
2016-01-12 23:34 0
2016-01-12 23:33 0

 

10 More Discussions You Might Find Interesting

1. Tips and Tutorials

Simple date and time calulation in BASH

The GNU date command in full of goodies but not when it comes to calculate a date or time difference. Here is what I came up with after looking to more than one solution. Code should be self explaining. #!/bin/bash date2stamp () { date --utc --date "$1" +%s } stamp2date (){ ... (0 Replies)
Discussion started by: ripat
0 Replies

2. Shell Programming and Scripting

Bash script error: missing destination file name operand.

Ok, i've been messing around in debian the past few days, setting up programs like subversion, mysql and logrotate. The purpose of this script is to use subversion to backup the binary logs. It runs in the cron every 2 hours or so (although I can't get my script to run properly atm, which is why... (1 Reply)
Discussion started by: cganly
1 Replies

3. Homework & Coursework Questions

Date comparison with 'string date having slashes and time zone' in Bash only

1. The problem statement, all variables and given/known data: I have standard web server log file. It contains different columns (like IP address, request result code, request type etc) including a date column with the format . I have developed a log analysis command line utility that displays... (1 Reply)
Discussion started by: TariqYousaf
1 Replies

4. Shell Programming and Scripting

Bash script - im missing something and cant's figure out what

I just put together a script for work that will essentially automate the migration of our Windows fileserver to my newly created Debian based SAMBA server. My script will create the necessary directories then copy the data over to my new server, after that it will set the ACL's by using... (3 Replies)
Discussion started by: binary-ninja
3 Replies

5. Shell Programming and Scripting

add up time with xx:yy format in bash how?

Hi, How can I add up a series of string like: and get a total as hour and minutes in a format like this: (3 Replies)
Discussion started by: bashily
3 Replies

6. Shell Programming and Scripting

Converting date/time and generating offsets in bash script

Hi all, I need a script to do some date/time conversion. It should take as an input a particular time. It should then generates a series of offsets, in both hour:minute form and number of milliseconds elapsed. For 03:00, for example, it should give back 04:02:07 (3727000ms*) 05:04:14... (2 Replies)
Discussion started by: emdan
2 Replies

7. Shell Programming and Scripting

date time stamps in bash

I'm looking for a way to have the "date" command output the date in a specific format. I'm not familiar with the different ways to use the date command at all. i read up on it, but i dont get how to manipulate it. i know that i can get the date format to give me a format like: 2012-10-13... (6 Replies)
Discussion started by: SkySmart
6 Replies

8. Shell Programming and Scripting

Simple date and time calulation in BASH

There is a closed Thread: <url>Here will be the url to the original post once I have 5 posts in this forum...</url> But a small bug had found his way into this very cool and simple code. #!/bin/bash date2stamp () { date --utc --date "$1" +%s } stamp2date (){ date --utc --date... (2 Replies)
Discussion started by: frood
2 Replies

9. Shell Programming and Scripting

Add current date and time

i have file 1.txt asdas|csada|13|03|10|04|23|A1|canberra sdasd|sfdsf|13|04|26|23|28|A1|sydney i want to add today's date and time in the end of each row expected output asdas|csada|13|03|10|04|23|A1|canberra|130430|1358 sdasd|sfdsf|13|04|26|23|28|A1|sydney|130430|1358 todays date... (10 Replies)
Discussion started by: radius
10 Replies

10. Programming

Find gaps in time data and replace missing time value and column 2 value by interpolation in awk

Dear all, I am kindly seeking assistance on the following issue. I am working with data that is sampled every 0.05 hours (that is 3 minutes intervals) here is a sample data from the file 5.00000 15.5030 5.05000 15.6680 5.10000 16.0100 5.15000 16.3450 5.20000 16.7120 5.25000... (4 Replies)
Discussion started by: malandisa
4 Replies
SIGNAL-SAFETY(7)					     Linux Programmer's Manual						  SIGNAL-SAFETY(7)

NAME
signal-safety - async-signal-safe functions DESCRIPTION
An async-signal-safe function is one that can be safely called from within a signal handler. Many functions are not async-signal-safe. In particular, nonreentrant functions are generally unsafe to call from a signal handler. The kinds of issues that render a function unsafe can be quickly understood when one considers the implementation of the stdio library, all of whose functions are not async-signal-safe. When performing buffered I/O on a file, the stdio functions must maintain a statically allocated data buffer along with associated counters and indexes (or pointers) that record the amount of data and the current position in the buffer. Suppose that the main program is in the middle of a call to a stdio function such as printf(3) where the buffer and associated variables have been partially updated. If, at that moment, the program is interrupted by a signal handler that also calls printf(3), then the second call to printf(3) will operate on incon- sistent data, with unpredictable results. To avoid problems with unsafe functions, there are two possible choices: 1. Ensure that (a) the signal handler calls only async-signal-safe functions, and (b) the signal handler itself is reentrant with respect to global variables in the main program. 2. Block signal delivery in the main program when calling functions that are unsafe or operating on global data that is also accessed by the signal handler. Generally, the second choice is difficult in programs of any complexity, so the first choice is taken. POSIX.1 specifies a set of functions that an implementation must make async-signal-safe. (An implementation may provide safe implementa- tions of additional functions, but this is not required by the standard and other implementations may not provide the same guarantees.) In general, a function is async-signal-safe either because it is reentrant or because it is atomic with respect to signals (i.e., its execu- tion can't be interrupted by a signal handler). The set of functions required to be async-signal-safe by POSIX.1 is shown in the following table. The functions not otherwise noted were required to be async-signal-safe in POSIX.1-2001; the table details changes in the subsequent standards. Function Notes abort(3) Added in POSIX.1-2003 accept(2) access(2) aio_error(3) aio_return(3) aio_suspend(3) See notes below alarm(2) bind(2) cfgetispeed(3) cfgetospeed(3) cfsetispeed(3) cfsetospeed(3) chdir(2) chmod(2) chown(2) clock_gettime(2) close(2) connect(2) creat(2) dup(2) dup2(2) execl(3) Added in POSIX.1-2008; see notes below execle(3) See notes below execv(3) Added in POSIX.1-2008 execve(2) _exit(2) _Exit(2) faccessat(2) Added in POSIX.1-2008 fchdir(2) Added in POSIX.1-2013 fchmod(2) fchmodat(2) Added in POSIX.1-2008 fchown(2) fchownat(2) Added in POSIX.1-2008 fcntl(2) fdatasync(2) fexecve(3) Added in POSIX.1-2008 ffs(3) Added in POSIX.1-2016 fork(2) See notes below fstat(2) fstatat(2) Added in POSIX.1-2008 fsync(2) ftruncate(2) futimens(3) Added in POSIX.1-2008 getegid(2) geteuid(2) getgid(2) getgroups(2) getpeername(2) getpgrp(2) getpid(2) getppid(2) getsockname(2) getsockopt(2) getuid(2) htonl(3) Added in POSIX.1-2016 htons(3) Added in POSIX.1-2016 kill(2) link(2) linkat(2) Added in POSIX.1-2008 listen(2) longjmp(3) Added in POSIX.1-2016; see notes below lseek(2) lstat(2) memccpy(3) Added in POSIX.1-2016 memchr(3) Added in POSIX.1-2016 memcmp(3) Added in POSIX.1-2016 memcpy(3) Added in POSIX.1-2016 memmove(3) Added in POSIX.1-2016 memset(3) Added in POSIX.1-2016 mkdir(2) mkdirat(2) Added in POSIX.1-2008 mkfifo(3) mkfifoat(3) Added in POSIX.1-2008 mknod(2) Added in POSIX.1-2008 mknodat(2) Added in POSIX.1-2008 ntohl(3) Added in POSIX.1-2016 ntohs(3) Added in POSIX.1-2016 open(2) openat(2) Added in POSIX.1-2008 pause(2) pipe(2) poll(2) posix_trace_event(3) pselect(2) pthread_kill(3) Added in POSIX.1-2013 pthread_self(3) Added in POSIX.1-2013 pthread_sigmask(3) Added in POSIX.1-2013 raise(3) read(2) readlink(2) readlinkat(2) Added in POSIX.1-2008 recv(2) recvfrom(2) recvmsg(2) rename(2) renameat(2) Added in POSIX.1-2008 rmdir(2) select(2) sem_post(3) send(2) sendmsg(2) sendto(2) setgid(2) setpgid(2) setsid(2) setsockopt(2) setuid(2) shutdown(2) sigaction(2) sigaddset(3) sigdelset(3) sigemptyset(3) sigfillset(3) sigismember(3) siglongjmp(3) Added in POSIX.1-2016; see notes below signal(2) sigpause(3) sigpending(2) sigprocmask(2) sigqueue(2) sigset(3) sigsuspend(2) sleep(3) sockatmark(3) Added in POSIX.1-2004 socket(2) socketpair(2) stat(2) stpcpy(3) Added in POSIX.1-2016 stpncpy(3) Added in POSIX.1-2016 strcat(3) Added in POSIX.1-2016 strchr(3) Added in POSIX.1-2016 strcmp(3) Added in POSIX.1-2016 strcpy(3) Added in POSIX.1-2016 strcspn(3) Added in POSIX.1-2016 strlen(3) Added in POSIX.1-2016 strncat(3) Added in POSIX.1-2016 strncmp(3) Added in POSIX.1-2016 strncpy(3) Added in POSIX.1-2016 strnlen(3) Added in POSIX.1-2016 strpbrk(3) Added in POSIX.1-2016 strrchr(3) Added in POSIX.1-2016 strspn(3) Added in POSIX.1-2016 strstr(3) Added in POSIX.1-2016 strtok_r(3) Added in POSIX.1-2016 symlink(2) symlinkat(2) Added in POSIX.1-2008 tcdrain(3) tcflow(3) tcflush(3) tcgetattr(3) tcgetpgrp(3) tcsendbreak(3) tcsetattr(3) tcsetpgrp(3) time(2) timer_getoverrun(2) timer_gettime(2) timer_settime(2) times(2) umask(2) uname(2) unlink(2) unlinkat(2) Added in POSIX.1-2008 utime(2) utimensat(2) Added in POSIX.1-2008 utimes(2) Added in POSIX.1-2008 wait(2) waitpid(2) wcpcpy(3) Added in POSIX.1-2016 wcpncpy(3) Added in POSIX.1-2016 wcscat(3) Added in POSIX.1-2016 wcschr(3) Added in POSIX.1-2016 wcscmp(3) Added in POSIX.1-2016 wcscpy(3) Added in POSIX.1-2016 wcscspn(3) Added in POSIX.1-2016 wcslen(3) Added in POSIX.1-2016 wcsncat(3) Added in POSIX.1-2016 wcsncmp(3) Added in POSIX.1-2016 wcsncpy(3) Added in POSIX.1-2016 wcsnlen(3) Added in POSIX.1-2016 wcspbrk(3) Added in POSIX.1-2016 wcsrchr(3) Added in POSIX.1-2016 wcsspn(3) Added in POSIX.1-2016 wcsstr(3) Added in POSIX.1-2016 wcstok(3) Added in POSIX.1-2016 wmemchr(3) Added in POSIX.1-2016 wmemcmp(3) Added in POSIX.1-2016 wmemcpy(3) Added in POSIX.1-2016 wmemmove(3) Added in POSIX.1-2016 wmemset(3) Added in POSIX.1-2016 write(2) Notes: * POSIX.1-2001 and POSIX.1-2004 required the functions fpathconf(3), pathconf(3), and sysconf(3) to be async-signal-safe, but this requirement was removed in POSIX.1-2008. * If a signal handler interrupts the execution of an unsafe function, and the handler terminates via a call to longjmp(3) or siglongjmp(3) and the program subsequently calls an unsafe function, then the behavior of the program is undefined. * POSIX.1-2003 clarified that if an application calls fork(2) from a signal handler and any of the fork handlers registered by pthread_atfork(3) calls a function that is not async-signal-safe, the behavior is undefined. A future revision of the standard is likely to remove fork(2) from the list of async-signal-safe functions. Deviations in the GNU C library The following known deviations from the standard occur in the GNU C library: * Before glibc 2.24, execl(3) and execle(3) employed realloc(3) internally and were consequently not async-signal-safe. This was fixed in glibc 2.24. * The glibc implementation of aio_suspend(3) is not async-signal-safe because it uses pthread_mutex_lock(3) internally. SEE ALSO
sigaction(2), signal(7), standards(7) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. Linux 2017-03-13 SIGNAL-SAFETY(7)
All times are GMT -4. The time now is 04:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy