Learning when was the last time a file is accessed - operating-system

I was wondering if learning when was the last time a file is accessed is possible. I mean like when a .dll file in windows is used by any other program. I wonder if are there any features in any operating system that keeps a file's last access date, or extensions.
Thanks!

Unix provides the stat command or the fstat() function to fetch the last access time of a file.
eos$ stat file
File: `file'
Size: 280486 Blocks: 548 IO Block: 4096 regular file
Device: 12h/18d Inode: 1963857568 Links: 1
Access: (0600/-rw-------) Uid: (83991/ vshesha) Gid: ( 108/ abcd)
Access: 2014-09-16 15:39:09.000000000 -0400
Modify: 2014-09-16 15:39:09.000000002 -0400
Change: 2014-09-16 15:39:09.000000000 -0400
For Windows see this post

This is a feature of a filesystem/OS. In case of Windows and it's default file system NTFS, you need to enable the feature first: http://www.groovypost.com/howto/microsoft/enable-last-access-time-stamp-to-files-folder-windows-7/
In the cmd prompt, Type in "fsutil behavior set disablelastaccess 0" and press enter.
Restart your PC for changes to take affect

Usually all file systems save the file access time.
For example, take a look at NTFS for Windows. Or ext2, and older version of the file system commonly used in linux.

Related

MacOS, AppleScript and Git

I have a project that will require reading a local repo and collecting the diff from the most recent commit and the one before it. I then need to do additional work with those diffs (add to an existing log file, make available for tech writers to edit existing API docs with the changes - might Slack them or API into Jira and build a ticket (like that option as it leaves a trail).
I can do the yeoman level work in an AppleScript, calling shell scripts when needed then parsing the data, and passing the cleaned data to the various applications/sites I need to. But other, less technical people will also be using this app and it would be nice to give them a simple UI to work with.
Anyway, after much digging through the Google, SO and other sources I was able to get a MacOS app working that can call an AppleScript and now I've run into a wall...
I can run this AppleScript from Script Editor and it works fine:
set strGitLog to do shell script "cd ~/Desktop/xxxxxx/Projects/UnifiedSDK/Repo/xxxxxx && git log -p -- file1.html"
"commit c39c6bb004d2e104b3f8e15a6125e3d68a5323ef
Author: Steve <xxxxxx#xxxxxx.com>
Date: Tue Oct 22 15:42:13 2019 -0400
Added deprecation warning to file1
diff --git a/file1.html b/file1.html
index b7af22b..9fdc781 100644
--- a/file1.html
+++ b/file1.html
## -51,6 +51,8 ##
<h2>Class Description</h2>
<p style=\"margin-bottom:10px;\">This is the description of the class</p>
+ <p style=\"margin-bottom:10px;\">Warning: This class is scheduled to be deprecated.</p>
+
<h3>Arguments:</h3>
<p style=\"margin-bottom:10px;\">These are the arguments that the class accepts</p>
...
but, if I place this script within a MacOS application:
script gitMessenger
property parent : class "NSObject"
to readMessage()
set strGitLog to do shell script "cd ~/Desktop/xxxxxx/Projects/UnifiedSDK/Repo/xxxxxx && git log -p -- file1.html"
log strGitLog
end readMessage
end script
I get this error message in the log:
fatal: Unable to read current working directory: Operation not permitted (error 128)
Which after checking seems to be a Git permissions error. If I pwd I am pointing to the right directory:
/Users/xxxxxx/Library/Containers/xxxxxx.GitMessenger/Data/Desktop/xxxxxx/Projects/UnifiedSDK/Repo/xxxxxx
and that directory has git initiated on it:
and it has permission for read/write to everyone. So I am a little at a loss right now how to get this to work. Any help or suggestions would be appreciated.

Maxima does not start on Sierra

I downloaded and installed the latest Ma version of Maxima from source forge. When I try to launch it, I get
“Maxima.app” is damaged and can’t be opened. You should move it to the Trash.
This happens with both available versions, the one with VTK and the one without VTK.
How can I get it running?
I have MacOS 10.12.6
and both versions are here:
https://sourceforge.net/projects/maxima/files/Maxima-MacOS/5.40.0-MacOSX/
Others have run into the same problem. I don't use MacOS so I'm not sure what the problem is. Anyway, take a look at this bug report: #3316: Maxima VTK for Mac 5.40 is corrupt. The person who submitted it reported they got it working by following the advice in the comments.
See also thread 39: https://sourceforge.net/p/maxima/support-requests/39/
This is a really important thread to the larger MacOS community.
I have a MacBook Pro running OS X El Capitan, which is locked down a few versions back from the current MacOS Mojave.
I spent an entire night trying to get every wxMaxima from 5.36 to 5.42 running without success - even compiling from sources.
In desperation I found the thread 39 and entered the line:
(setf sb-impl::default-external-format :utf-8)
into a ~home/.sbclrc file (/Users/myName/.sbclrc). It was only then that the GUI and the Maxima engine could connect and a normal session could be established. Maxima, its maintainers and its users are too important a world resource to be stymied by such an esoteric and non-obvious bug.
A user encountering this bug will first go into the preferences menu and start trying to make sure that the file addresses and port numbers are correct, but experimentation can corrupt these and lead to other problems.
In my case following excerpt from https://sourceforge.net/p/maxima/mailman/message/35910588/ helped:
(0) Double-click the icon of "Terminal.app" in the folder "/Applications/Utilities", then the command-line-user-interface window is opened.
(1) Move the current working directory to the location of the disc image with the command "cd". (e.g. "Downloads" folder)
$ cd $HOME/Downloads
(2) You can check the attribute with the command "ls -l#":
(You will be able to find "com.apple.quarantine" which is the name of the attribute.)
$ ls -l# ./*.dmg
-rw-r--r--# 1 name staff 471227521 6 24 23:17 ./Maxima-5.40.0-VTK-macOS.dmg
com.apple.quarantine 62
(3) Remove the attribute "com.apple.quarantine" with the command "xattr -d com.apple.quarantine ./*.dmg":
$ xattr -d com.apple.quarantine ./Maxima-5.40.0-VTK-macOS.dmg
(4) Verify that the attribute "com.apple.quarantine" was removed:
$ ls -l# ./*.dmg
-rw-r--r-- 1 name staff 471227521 6 24 23:17 ./Maxima-5.40.0-VTK-macOS.dmg
(5) Double-click the icon of the disc image file to open.
After that, you should install Maxima.app into your "Applications" folder ("/Applications"). And you should drag the Launchers icon from the disc image to another place of your filesystem. You can install launchers to anywhere you like.
Then you will be able to launch Maxima with Maxima.app or launchers.

Install4j varfile doesnt' read few variables

Installer is installed typically using GUI or console, we need unattended installation capability as well. Running the installer like this (in Linux):
myapp -q -c -varfile myfile.var
Installer installs the software successfully. Problem is it ignores some variables (not all variables). It doesn't read values for zServerPort$Long and zShutdownPort$Long variables and instead applies the default values configured in application.
Varfile is provided below
#install4j response file for Sw 4.6
#Mon Aug 11 19:55:46 PDT 2014
sys.adminRights$Boolean=true
choiceIsLicenseSelected=true
zDBUserName=user
zLaunchDesktopPostInstall$Boolean=false
zDBPassWord=password
sys.languageId=en
sys.installationDir=/opt/mydir
zServerPort$Long=85
zLicenseFilePath=/home/mydir/Desktop/license.lic
zMysqlPath=/usr/bin/mysql
zMysqlCnf=/etc/mysql/my.cnf
zDbPort$Long=3306
choiceInstallDir=/opt/mydir
zShutdownPort$Long=8015
zServerPort, zShutdownPort, choiceInstallDir, zMysqlPath are all installer variables. Reordering the variables didn't work either. Is the problem due to data type being Long ?
Is there a way to pass the values of these two variables zServerPort, zShutdownPort in some other way ?
Other idea am thinking is whether if the installer can know that it is being run in unattended mode and read these variables from command line ?
Most likely, the defaults are applied with a code snippet and not through the initial values of form components.
In those code snippets (i.e. in a "Run script" action"), you have to check whether the value is already defined or not. For example:
if (context.getVariable("variableName") != null) {
context.setVariable("variableName"), 100L);
}

Where to find logs for a cloud-init user-data script?

I'm initializing spot instances running a derivative of the standard Ubuntu 13.04 AMI by pasting a shell script into the user-data field.
This works. The script runs. But it's difficult to debug because I can't figure out where the output of the script is being logged, if anywhere.
I've looked in /var/log/cloud-init.log, which seems to contain a bunch of stuff that would be relevant to debugging cloud-init, itself, but nothing about my script. I grepped in /var/log and found nothing.
Is there something special I have to do to turn logging on?
The default location for cloud init user data is already /var/log/cloud-init-output.log, in AWS, DigitalOcean and most other cloud providers. You don't need to set up any additional logging to see the output.
You could create a cloud-config file (with "#cloud-config" at the top) for your userdata, use runcmd to call the script, and then enable output logging like this:
output: {all: '| tee -a /var/log/cloud-init-output.log'}
so I tried to replicate your problem. Usually I work in Cloud Config and therefore I just created a simple test user-data script like this:
#!/bin/sh
echo "Hello World. The time is now $(date -R)!" | tee /root/output.txt
echo "I am out of the output file...somewhere?"
yum search git # just for fun
ls
exit 0
Notice that, with CloudInit shell scripts, the user-data "will be executed at rc.local-like level during first boot. rc.local-like means 'very late in the boot sequence'"
After logging in into my instance (a Scientific Linux machine) I first went to /var/log/boot.log and there I found:
Hello World. The time is now Wed, 11 Sep 2013 10:21:37 +0200! I am
out of the file. Log file somewhere? Loaded plugins: changelog,
kernel-module, priorities, protectbase, security,
: tsflags, versionlock 126 packages excluded due to repository priority protections 9 packages excluded due to repository
protections ^Mepel/pkgtags
| 581 kB 00:00
=============================== N/S Matched: git =============================== ^[[1mGit^[[0;10mPython.noarch : Python ^[[1mGit^[[0;10m Library c^[[1mgit^[[0;10m.x86_64 : A fast web
interface for ^[[1mgit^[[0;10m
...
... (more yum search output)
...
bin etc lib lost+found mnt proc sbin srv tmp var
boot dev home lib64 media opt root selinux sys usr
(other unrelated stuff)
So, as you can see, my script ran and was rightly logged.
Also, as expected, I had my forced log 'output.txt' in /root/output.txt with the content:
Hello World. The time is now Wed, 11 Sep 2013 10:21:37 +0200!
So...I am not really sure what is happening in you script.
Make sure you're exiting the script with
exit 0 #or some other code
If it still doesn't work, you should provide more info, like your script, your boot.log, your /etc/rc.local, and your cloudinit.log.
btw: what is your cloudinit version?

Not getting UUID from diskutil on OSX

Running Mac OSX 10.7.5
I want to enable NTFS on a USB3 external hard disk and need the UUID to do it (http://ntfsonmac.com) but diskutil is refusing to give me the UUID. I start with:
diskutil info /Volumes/HD-PCTU3/
then from this:
diskutil info disk2s1
Device Identifier: disk2s1
Device Node: /dev/disk2s1
Part of Whole: disk2
Device / Media Name: Untitled 1
Volume Name: HD-PCTU3
Escaped with Unicode: HD-PCTU3
Mounted: Yes
Mount Point: /Volumes/HD-PCTU3
Escaped with Unicode: /Volumes/HD-PCTU3
File System Personality: NTFS
Type (Bundle): ntfs
Name (User Visible): Windows NT File System (NTFS)
Partition Type: Windows_NTFS
OS Can Be Installed: No
Media Type: Generic
Protocol: USB
SMART Status: Not Supported
Total Size: 500.1 GB (500107804672 Bytes) (exactly 976773056 512-Byte-Blocks)
Volume Free Space: 499.9 GB (499896778752 Bytes) (exactly 976360896 512-Byte-Blocks)
Device Block Size: 512 Bytes
Read-Only Media: No
Read-Only Volume: Yes
Ejectable: Yes
Whole: No
Internal: No
but as can be seen there is no UUID displayed. Any ideas why and/or how to get the UUID?
The only way I've been able to find involves a somewhat poorly documented feature of the hfs.util.
Run the diskutil command and then copy/remember/save the Device Identifier:
diskutil info /Volumes/my_drive_label | grep "Device Identifier"
You can use the hfs.util with the Device Identifier (replacing disk2s1 below) from diskutil to (re)generate a UUID for your volume:
/System/Library/Filesystems/hfs.fs/hfs.util -s disk2s1
Keep in mind this won't work for every volume, if the volume is not an HFS drive than it may not work, and other Filesystem/*.fs/*.util commands may not have a -s verb to generate UUIDs.
UPDATE
In Yosemite and after the -s flag has been disabled at the source level. I haven't been able to find a pre-modified version of hfs.util, but you can do it yourself using the information found in this Superuser question, summarized here:
Download the hfs.util source from Apple and extract it to a temporary folder
Download hfs_fsctl.h from Apple and put it in the hfs.util folder
Change line 47 of hfsutil_jnl.c into #include <hfs_fsctl.h>
Change line 80 of hfsutil_main.c into #include <System/uuid/uuid.h>
Change line 81 of hfsutil_main.c into static unsigned char kFSUUIDNamespaceSHA1[] = {0xB3,0xE2,0x0F,0x39,0xF2,0x92,0x11,0xD6,0x97,0xA4,0x00,0x30,0x65,0x43,0xEC,0xAC}; (replacing the include line)
Also add #define HFS_UUID_SUPPORT 1 to hfsutil_main.c
There might still be something missing in the argument parsing section if the above doesn't work, please reference the Superuser question and comment if I've missed something.
Some people have also reported that it may be possible to use Gparted to change the UUID of a drive.
I'm on Mac OS X 10.6.8 and bought NTFS 4TB Seagate USB3.0 drive.
Plugged in, Mac allowed me to read files from it, but not write to it. When I select 'Get Info' for the volume/disk, I see 'You can read only' under 'Sharing & Permissions'.
I copied a large file from Windows 10 to the USB Drive, worked fine. I then downloaded the file to Mac, worked fine, but won't allow me to write anything from Mac to the USB drive, or make any changes to it eg. delete or rename files on the USB drive.
My reason for getting this USB drive formatted in NTFS was to copy files from Mac larger than 4GB to Windows for redundant backup, because of 4GB limit in FAT.
One solution I found online was to sudo echo UUID to /etc/fstab
When I diskutil info, I don't get UUID.
I also see the following extracts:
File System Personality: NTFS
Type (Bundle): ntfs
Name (User Visible): Windows NT File System (NTFS)
&
Read-Only Media: No
Read-Only Volume: Yes
Ejectable: Yes
My solution was to download Samsung NTFS for Mac Driver from:
https://www.seagate.com/au/en/support/downloads/item/samsung-ntfs-driver-master-dl/
After installation & reboot, I noticed the following changes:
When I select 'Get Info' for the volume/disk, I see 'You can read and write' under 'Sharing & Permissions'.
2.
File System Personality: UFSD_NTFS
Type (Bundle): ufsd_NTFS
Name (User Visible): Windows NT Filesystem
3.
Read-Only Media: No
Read-Only Volume: No
Ejectable: Yes
The readme file (pdf) that comes with the download says NTFS features also work in Mac for the USB drive.
Now I can read/write to the disk, and is also visible in Finder. I've tested read & write speeds with a 2GB file, and don't see any difference in performance/speed between the NTFS & HFS+ Journaled volumes.
Finally after 2 days of reading about sudo, hfs.util & diskutil, I can now get back to backing up data from Mac 10.6 to USB NTFS drive.