Skip to content

Instantly share code, notes, and snippets.

@shreyb
shreyb / activate_gpg_key.sh
Created August 29, 2025 16:14
Quick little script I use to activate my GPG key on my dev nodes
#!/bin/sh
GPG=$(which gpg)
if [[ $? -ne 0 ]]; then
echo "No gpg found. Exiting"
exit 1
fi
TEMP=$(mktemp)
${GPG} -s ${TEMP}

The new jobsub_api allows users to import and use jobsub functionality programmatically through high-level functions that mimic the jobsub_* commands. The main functions users will use are jobsub_api.submit() and jobsub_api.q(), similar to how users now mainly use jobsub_submit and jobsub_q. For the most part, the function signatures will mirror the command-line options - for example, jobsub_api.submit() accepts an f argument that corresponds to the -f command line option, a tar_file_name argument that corresponds to the --tar-file-name option, etc. Both jobsub_api.submit() and jobsub_api.q() will raise jobsub_api.JobsubAPIErrors if they fail. Like the example below shows, users can catch that error to handle it as they see fit.

jobsub_fetchlog translates to a method on the returned class (jobsub_api.SubmittedJob) from jobsub_api.submit().

Coding Example

 import sys
 sys.path.append('/opt/jobsub_lite/lib')
 import jobsub_api
@shreyb
shreyb / parse_voms_production.py
Last active March 2, 2021 16:30
This is a little script to parse the VOMS logs at Fermilab (notice the regexes look for fnal.gov VOMS servers) to grab all the production users.
import argparse
from collections import Counter, defaultdict, namedtuple
from datetime import datetime, timedelta
from functools import partial
import gzip
import pathlib
import re
# Regexes
pid_production_line_regex = re.compile('^(\w{3} \w{3}(?: ){1,2}\d{1,2} \d{2}\:\d{2}\:\d{2} \d{4})\:voms\d\.fnal\.gov\:vomsd\[(\d+)\].+Issued FQAN: .+\/Role=Production\/Capability=NULL\"$')

Keybase proof

I hereby claim:

  • I am shreyb on github.
  • I am sbhat (https://keybase.io/sbhat) on keybase.
  • I have a public key ASDekFSrE2NiV3z8Ikq2xuGimbAE19jOrwQLE8N5_hgb7Qo

To claim this, I am signing this object:

@shreyb
shreyb / test_unique_arg_parse.py
Last active March 9, 2020 17:06
jobsub_client arg parser (next version) that can support unique flags.
#!/usr/bin/python
import argparse
from collections import defaultdict
import pytest
num_changes_limit = 1
class JobsubClientNamespace(argparse.Namespace):
@shreyb
shreyb / double_optparse.py
Created November 19, 2018 22:10
Quick mockup for checking for doubled command line options
from optparse import Option, OptionParser
# Adapted from https://stackoverflow.com/questions/23032514/argparse-disable-same-argument-occurences and optparse docs
class MyOption(Option):
ACTIONS = Option.ACTIONS + ("unique_store",)
STORE_ACTIONS = Option.STORE_ACTIONS + ("unique_store",)
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("unique_store",)
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("unique_store",)
@shreyb
shreyb / rebuild_all_images.sh
Created September 21, 2017 20:16
Script to rebuild all GRACC reporting images where dockerfiles live
#!/bin/sh
# This script is to rebuild all the images (assuming no version bump) with a new RPM. This is useful, for example, if there's a minor bug found in testing. We can rebuild all the Docker images and push them automatically
# The script also commits the changed rpm to the git repo master branch
# Constants
DOCKERDIR=${HOME}/Project/email_reports-docker
RPMDIR=${HOME}/RPMDocker/rpm_out
BASEDIR=${DOCKERDIR}/base
FIFEBASEDIR=${DOCKERDIR}/fife
@shreyb
shreyb / build_gracc_rpm.sh
Last active July 6, 2017 17:41
Build the gracc-reporting RPM automatically from tarball
#!/bin/sh
TARFILEPATH=`ls -t ${HOME}/rpmbuild/SOURCES/*.tar.gz | head -n 1`
TARFILE=${TARFILEPATH##*/}
SOURCESDIR=${HOME}/rpmbuild/SOURCES
SPECSDIR=${HOME}/rpmbuild/SPECS
RELEASE=`echo ${TARFILE%.tar.gz}`
TMPDIR=/tmp/${RELEASE}
PATH_TO_SPEC=src/graccreports/config/gracc-reporting.spec # Within the tarball
@shreyb
shreyb / install_gracc_rep.sh
Created July 6, 2017 15:57
Script for installing a new gracc-reporting tarball on GRACC
#!/bin/sh
# VARIABLES
SYMLINKNAME=${HOME}/gracc-reporting
GREPGRACCSTRING="^gracc-reporting-[0-9]\.[0-9]+(\.[0-9]+)?$"
ARCHIVEDIR=${HOME}/gracc-reporting-old
VENVNAME=gracc_venv
# Part 1: Setup of dir structure
cd $HOME
@shreyb
shreyb / copypics.py
Created June 20, 2017 21:58
Quick script to go through JPEGS and copy files created after a certain date to a new subdirectory
#!/usr/bin/python
import subprocess
import sys
import os
from datetime import datetime
from time import sleep
from shutil import copy2, rmtree
import re
import json