Scheduled Git Auto-commit: Showing I’m not lazy on my GitHub profile

Scheduled Git Auto-commit: Showing I’m not lazy on my GitHub profile

Hoću da imam script koji će moj notes automatski push-ovati na svakih 10 minuta bez moje intervencije.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh
#
# Don't forget to
# chmod +x /usr/local/bin/autocommit.sh
#
# Ensure path is proper in crontab
# PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

auto_commit_and_push() {
    local dir=$1
    cd "$dir" || exit
    git add --all
    git commit -am "-"
    ping -c 1 github.com > /dev/null && git push origin --all || echo "not connected in $dir"
}

auto_commit_and_push /Users/Storage/Treasury
# auto_commit_and_push /path/to/another/repository
# auto_commit_and_push /path/to/yet/another/repository

And call it from crontab -e

1
2
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
*/10 * * * * autocommit.sh >/dev/null

Idea was from How to automate your git workflow on windows | by Ilesanmi Temitope | Medium


Prijavljivao mi je grešku:

fatal: could not read Username for 'https://github.com': Device not configured

čim pokrenem script-e iz crontab.

System is not finding the credentials, pa sam probao sa setovanjem HOME varijable, i nije,

Furthermore, you have the option to write the cron task in the specified format (execute crontab -e and insert the following cronjob).

          • /bin/bash -l -c ‘cd /var/www/project && ./autogit-project.sh » /home/cron_log.log 2>&1’

You can examine the cron jobs of the intended user responsible for


BackwardJet/Cron-Auto-Push: A script to automate pushing to Github

U repo folderu moraš pokrenuti:

1
2
3
git config user.name "Vladan Colovic"
git config user.email "cvladan@gmail.com"
cat .git/config

https://askubuntu.com/a/814235

Eh. [Git + mac]: Schedule your git commands with launchd | { Ellis Min } I odličan je ovaj tool, baš odličan: Launched - A Plist Generator


Problem: Keychain access in crontab

git config credential.helper

result: osxkeychain

Once installed, just tell Git to use the KeyChain to store your credentials:

git config –global credential.helper osxkeychain

Next time you clone a repo via HTTPS, you’ll be prompt for granting access to KeyChain. That’s it.

Suština je da crontab ne vidi keychain, ali hoće da interact with the “System roots” keychain unless you specify a keychain as I’ve done in my crontab, tako da sam pokušao

Git’s built-in credential helpers (Windows: wincred, macOS: osxkeychain, Linux: gnome-keyring/libsecret)

Međutim, imao sam grešku u crontab-u, pa sam morao da prebacim na unencrypted plaintext storovanje u fajlu: GitHub Commit Bot to Stack Your Contributions Graph - blog.karenying.com

1
2
git config --global credential.helper store
~/.git-credentials

I onda je proradilo, ali to nije baš idealno rešenje.

I dalje tražim rešenje da zadržim keychain kao mesto za password-e:

1
git config --global credential.helper osxkeychain

Takođe, sa lakoćom radi with the mac launchd with no password prompt and also Apple says that better way is to use launchd instead of cron


Copy the github.com passwords to the system keychain.

Probaj da pokreneš u CLI security list-keychains gde dobijaš i “login.keychain-db” i “System.keychain”, a zatim u crontab

*/1  * * * * security list-keychains -d user

i videćeš da user keychain nije čitan iz crontab-a, jer dobijaš samo “/Library/Keychains/System.keychain”

Pokreni alat Keychain Access, zatim uradi search za “github.com”, zatim desni click i “Copy”, zatim opy that service and password from login.keychians to syste,.keychains as cronjob by default looks into system keychains and not login keychains. This worked for me.

How to access Keychain of my user from cron? - Ask Different


Pokušao sam i ovo, ali to ima veze samo sa SSH:

1
2
3
cat ~/.ssh/config
# Host *
#    UseKeychain yes

Battling with SSH, cron jobs, and macOS Keyring · Nicola Iarocci

Obrati pažnju da ima find-generic-password i find-internet-password

1
2
security find-internet-password -w -s 'github.com' -a 'username'
sudo security add-internet-password -s 'sisoje'  -a 'username' -w 'password123' "/Library/Keychains/System.keychain"

kako bi bilo da dodam keychain u search list?

Ovako:

Cron would only load from the system keychain, so the password has to be there.

date 20. Dec 2023 | modified 10. Jun 2024
filename: Workflow » Second Brain » Scheduled Git Auto-commit